Telerik Reporting Error: sqlDataSource does not exist in the current context - telerik-reporting

I am trying to create a SqlDataSource using Telerik Reporting and am getting errors using the exact code in the documentation attempting to connect to AdventureWorks database:
SqlDataSource sqlDataSource = new SqlDataSource();
sqlDataSource.ProviderName = "System.Data.SqlClient";
sqlDataSource.ConnectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True";
sqlDataSource.SelectCommand = "SELECT * FROM Production.Product";

The code is placed inside of the body of the class, but it should be placed in a method instead. Use object initializer like this:
SqlDataSource sqlDataSource = new SqlDataSource
{
ProviderName = "System.Data.SqlClient",
ConnectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True",
SelectCommand = "SELECT * FROM Production.Product"
}
or move the initialization code in a separate method.

Related

How to pass dynamic connectionstring with username and password directly in SSRS using C#?

I am using SSRS for reporting purpose in my application.In SSRS i am using Embedded DataSource for fetching data.
I want to pass dynamic connection string in c# code to that datasource so based on connection string parameter it will fetch data assordingly.
Is that possible ?
//Here you can fetch Database Name dynamically and assign to Initial
Catalog for preparing dynamic connection string.
string conStr = #"Data Source=DILIPPC\SQLEXPRESS;Initial Catalog=Student";
// Fetch all datasources
var dataSources = this.reportViewer1.ServerReport.GetDataSources();
List<DataSourceCredentials> credentials = new List<DataSourceCredentials();
foreach (var dataSource in dataSources)
{
DataSourceCredentials credential = new DataSourceCredentials();
credential.Name = dataSource.Name;
credential.UserId = " "; // Wirte username of your connection
credential.Password = " "; // Wirte password of your connection
credentials.Add(credential);
}
this.reportViewer1.ServerReport.SetDataSourceCredentials(credentials);
// Added ConStr parameter and pass this parameter to SSRS report.
ReportParameter rptPar = new ReportParameter("ConStr", conStr);
reportViewer1.ServerReport.SetParameters(rptPar);

SSRS Report cache disable using "rs:ClearSession"

I found a way to achieve this that using the query string "rs:ClearSession" have to pass in URL.
Below is my code ASP.NET SSRS Reportviewer integarating page,
rptvw.ProcessingMode = ProcessingMode.Remote;
rptvw.ServerReport.ReportServerUrl = new Uri("http://localhost/reportserver");
rptvw.ServerReport.ReportPath = "/Northwind/NewNorthwind";
ReportParameter[] param = new ReportParameter[1];
param[0] = new ReportParameter("CustomerID", txtparam.Text);
rptvw.ServerReport.SetParameters(param);
rptvw.ServerReport.Refresh();
Question is where should I pass the query string "rs:ClearSession". I tried in above ReportServerUrl and ReportPath but still getting error might be I have done any syntax errors.
Where and how to pass the query string "rs:ClearSession" in URL ?

MySqlClient: SaveChanges in ASP.NET doesn't update DB table

I'm using MySql database in ASP.NET MVC 4 project with MySqlClient (MySQL Connector .NET ).
In the References are dlls: MySql.Data, MySql.Data.Entry, MySql.Web
Selects from MySql database executes successfully, but inserts and updates are doesn't executes. No errors, no exceptions.
code №1:
var connectionString = "Server=my_server;Uid=my_login;Pwd=my_password;Old Guids=true;persist security info=True;database=clientest;allow zero datetime=True;convert zero datetime=True";
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
String commandText = "update testdb.visit set doctor_spec='dentist' where visit_id = 2;";
MySqlCommand cmd = new MySqlCommand(commandText, conn);
cmd.CommandType = System.Data.CommandType.Text;
conn.Open();
cmd.ExecuteNonQuery();
}
No errors, no exception, but the table hasn't updates
code №2
using (var db = new MySqlDBEntities())
{
var vx = (from v in db.visit where v.visit_id == 1 select v).FirstOrDefault();
vx.doctor_spec = "dentist";
db.SaveChanges();
}
No errors, no exception, but the table hasn't updates.
What's wrong? Maybe another way for using MySql in ASP.NET MVC projects?
P.S. Sorry for my poor English :(
check connection in web config and find Correctly Data File
After Do Save Change Successfully any Edited Or New Entity Changes is Update
check this code too
* from v in db.visit /* db.visits */ where *

ADODB Command failing Execute with parameterised SQL query

I have the following JScript code:
var conn = new ActiveXObject ("ADODB.Connection");
conn.Open("Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=blah_blah_blah;User=foo;Password=bar;");
var cmd = new ActiveXObject("ADODB.Command");
cmd.ActiveConnection = conn;
var strSQL = "SELECT id FROM tbl_info WHERE title LIKE :search ORDER BY id";
var search = "test";
try{
cmd.CommandText = strSQL;
var param = cmd.CreateParameter(':search', 200, 1, 100, search);
cmd.Parameters.Append(param);
var rs = cmd.Execute();
}
catch (ex) {
Application.Alert("Error retrieving id information from database.");
}
I've verified (by printing them) that the Connection object is set to be the Command's ActiveConnection, the parameter object has the correct value and the Command object has the correct SQL query as its CommandText. I also inserted an alert statement after each line in the try block to see where the error was occuring - it's fine after cmd.Parameters.Append but the exception gets thrown upon running the Execute statement.
I've tried displaying the actual exception but it's just a generic 'Object error' message.
The query executes fine and returns the correct result set when I just execute the SQL query (without the parameter) straight through the Connection object, but seems to fail when I use a parameterised query with the Command object.
As far as I can see all settings and properties of the Command and Connection objects are correct but for whatever reason it's throwing an exception.
Any help with this would be much appreciated.
With ODBC and ADO, generally speaking, a question mark ? is used as the placeholder for parameters. Parameters are bound in the order they are appended to the Parameters collection to the placeholders in the command. In your example, replace strSQL with:
var strSQL = "SELECT id FROM tbl_info WHERE title LIKE ? ORDER BY id";
You can still name the parameter that you create, but the only purpose it would serve is to be able to reference it by name later (e.g., with cmd.Parameters.Item(":search")).

Connection Manager in Script Component

How will we use Connection Manager in Script component, using OLEDB Provider ? I had tried using Connection Manager with OLEDB Provider and SQL, but failed. what is the correct way to use ?
The syntax is different between a Script Task and a Script Component. Check out this article for more than a couple side-by-side comparisons:
http://msdn.microsoft.com/en-us/library/ms136031.aspx
This is well documented on MSDN, covering both VB and C# type of scripts: http://msdn.microsoft.com/en-us/library/ms136018.aspx
IDTSConnectionManager100 connMgr = this.Connections.ADONetAppStaging ; //this we need to give name in connection manager in script component
SqlConnection myADONETConnection = new SqlConnection();
myADONETConnection = (SqlConnection)(connMgr.AcquireConnection(null));
//Read data from table or view to data table
string query = "Select top 10 * From ##AP_Stagging_Temp_ExportWODuplicates Order by 1,2,3 asc ";
// string query = "Select * From ##AP_Stagging_Temp_For_JLL_ExportWODuplicates order by 1,2,3 asc ";
SqlDataAdapter adapter = new SqlDataAdapter(query, myADONETConnection);
DataTable dtExcelData = new DataTable();
adapter.Fill(dtExcelData);
myADONETConnection.Close();