Dynamic crystal report connection string required for transfer application dev to test.Normally developer working in devlopment server and after complet the development it will deploy the application into TEST or Production Server .In this case crystal report have not worked if you are specially using oracle stored procedure .Here I explain you how to create function for dynamic connection with stored procedure.
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
public ReportDocument ConnectionInfo(ReportDocument rpt)
{
ReportDocument crSubreportDocument;
string[] strConnection = ConfigurationManager.ConnectionStrings[("AppConn")].ConnectionString.Split(new char[] { ';' });
Database oCRDb = rpt.Database;
Tables oCRTables = oCRDb.Tables;
CrystalDecisions.CrystalReports.Engine.Table oCRTable = default(CrystalDecisions.CrystalReports.Engine.Table);
TableLogOnInfo oCRTableLogonInfo = default(CrystalDecisions.Shared.TableLogOnInfo);
ConnectionInfo oCRConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
oCRConnectionInfo.ServerName = strConnection[0].Split(new char[] { '=' }).GetValue(1).ToString();
oCRConnectionInfo.Password = strConnection[2].Split(new char[] { '=' }).GetValue(1).ToString();
oCRConnectionInfo.UserID = strConnection[1].Split(new char[] { '=' }).GetValue(1).ToString();
for (int i = 0; i < oCRTables.Count; i++)
{
oCRTable = oCRTables[i];
oCRTableLogonInfo = oCRTable.LogOnInfo;
oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo;
oCRTable.ApplyLogOnInfo(oCRTableLogonInfo);
if (oCRTable.TestConnectivity())
//' If there is a "." in the location then remove the
// ' beginning of the fully qualified location.
//' Example "dbo.northwind.customers" would become
//' "customers".
oCRTable.Location = oCRTable.Location.Substring(oCRTable.Location.LastIndexOf(".") + 1);
}
for (int i = 0; i < rpt.Subreports.Count; i++)
{
{
// crSubreportObject = (SubreportObject);
crSubreportDocument = rpt.OpenSubreport(rpt.Subreports[i].Name);
oCRDb = crSubreportDocument.Database;
oCRTables = oCRDb.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in oCRTables)
{
oCRTableLogonInfo = aTable.LogOnInfo;
oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo;
aTable.ApplyLogOnInfo(oCRTableLogonInfo);
if (aTable.TestConnectivity())
//' If there is a "." in the location then remove the
// ' beginning of the fully qualified location.
//' Example "dbo.northwind.customers" would become
//' "customers".
aTable.Location = aTable.Location.Substring(aTable.Location.LastIndexOf(".") + 1);
}
}
}
// }
rpt.Refresh();
return rpt;
}
This will not work with oracle packages.
thanks good information .. waiting for any new updates the helps me in my work (^_^)
ReplyDeleteshall apply this in my new reports . hope it will solve lot of deployment issues of crystal report. thanks for the update.
ReplyDeleteWoOoOoW this is so helpful ...
ReplyDeletegood job :)
yeh cheez mairay azeez :)
ReplyDeleteI have created web application in asp.net 2010 with crystal report.
ReplyDeletecrystal rport is established using stored procedure with oledb connection.
Crystal report works fine on local but not on live,it showes error failed to open connection database vendor code 17.
want proper solution..
This comment has been removed by the author.
ReplyDeleteIt works perfectly well.
ReplyDeleteGreat Article
ReplyDeleteASP.NET Training
Dot Net Training in Chennai
ASP NET Training
ASP.NET Online Training
Dot Net Training in Chennai
.Net Online Training
.net training online
Dot Net Online Training
C# Training
Core C# Interview Questions
Dot Net Interview Questions
This comment has been removed by the author.
ReplyDeletecan we change provider from SQLOLEDB to SQLNCLI11 dynamically using vb.net?
ReplyDelete