Hi,
CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
string oldServerName = "OldServer";
string newServerName = "NewServer";
string oldDatabaseName = "OldDatabase";
string newDatabaseName = "NewDatabase";
string userID = "MyUserID";
string password = "MyPassword";
report.Load(@"C:\My Crystal Reports\Report Name.rpt");
// Change the server name and database in main reports
foreach (CrystalDecisions.Shared.IConnectionInfo connection in report.DataSourceConnections)
{
if ((String.Compare(connection.ServerName, oldServerName, true) == 0) &&
(String.Compare(connection.DatabaseName, oldDatabaseName, true) == 0))
{
// SetConnection can also be used to set new logon and new database table
report.DataSourceConnections[oldServerName, oldDatabaseName].SetConnection(
newServerName, newDatabaseName, userID, password);
}
}
// Change the server name and database in subreport
foreach (CrystalDecisions.CrystalReports.Engine.ReportDocument subReport in report.Subreports)
{
foreach (CrystalDecisions.Shared.IConnectionInfo connection in subReport.DataSourceConnections)
{
if ((String.Compare(connection.ServerName, oldServerName, true) == 0) &&
(String.Compare(connection.DatabaseName, oldDatabaseName, true) == 0))
{
// SetConnection can also be used to set new logon and new database table
subReport.DataSourceConnections[oldServerName, oldDatabaseName].SetConnection(
newServerName, newDatabaseName, userID, password);
}
}
}
Chk the above code
Thanks
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
MY Blog Hacking Inside .net exe