Reputation: 1526
Is it possible to convert crystalreport's Provider from 'SQLNCLI' to 'SQLOLEDB' by code "c#"
I have tried with following code but did not work.
TableLogOnInfo logoninfo;
foreach (CrystalDecisions.CrystalReports.Engine.Table tbcurrent in rptH.Database.Tables)
{
logoninfo = new TableLogOnInfo();
logoninfo.ConnectionInfo.DatabaseName = connectionInfo.DatabaseName;
logoninfo.ConnectionInfo.ServerName = connectionInfo.ServerName;
logoninfo.ConnectionInfo.UserID = connectionInfo.UserID;
logoninfo.ConnectionInfo.Password = connectionInfo.Password;
tbcurrent.ApplyLogOnInfo(logoninfo);
}
rptH.SetDatabaseLogon(connectionInfo.UserID, connectionInfo.Password, connectionInfo.ServerName, connectionInfo.DatabaseName, true);
for (int i = 0; i < rptH.Subreports.Count; i++)
{
foreach (CrystalDecisions.CrystalReports.Engine.Table tbcurrent in rptH.Subreports[i].Database.Tables)
{
logoninfo = new TableLogOnInfo();
logoninfo.ConnectionInfo.DatabaseName = connectionInfo.DatabaseName;
logoninfo.ConnectionInfo.ServerName = connectionInfo.ServerName;
logoninfo.ConnectionInfo.UserID = connectionInfo.UserID;
logoninfo.ConnectionInfo.Password = connectionInfo.Password;
tbcurrent.ApplyLogOnInfo(logoninfo);
}
rptH.Subreports[i].SetDatabaseLogon(connectionInfo.UserID, connectionInfo.Password, connectionInfo.ServerName, connectionInfo.DatabaseName, true);
}
Upvotes: 1
Views: 450
Reputation: 649
I am not sure if this can be done as the connection type seems to be stored in the .rpt
file.
But you can try use native .Net API to retrieve database selection into a System.Data.DataSet
/ System.Data.DataTable
instance and call Table.SetDataSource()
to set as the table data source, so you do not need to care about TableLogOnInfo
object, but please ensure the scheme matches that of the report.
Below sample codes are from Crystal Reports .NET API Guide:
private void SetDataSource
(string conn, string query, DataSet dataSet)
{
OleDbConnection oleConn = new OleDbConnection(conn);
OleDbDataAdapter oleAdapter = new OleDbDataAdapter();
oleAdapter.SelectCommand = new OleDbCommand(query, oleConn);
oleAdapter.Fill(dataSet, "Customer");
reportDocument.Database.Tables["Customer"].SetDataSource (dataSet);
}
Besides, ReportDocument
also has SetDataSource()
method, so you can set the data source for the whole report.
Upvotes: 1