Reputation: 708
I'm developing a local app with friends and we're using svn, but we have crystal reports, but it saves the last server used by one of my friends when doing the commit. I tried changing the server programatically using this piece of code, but it didn't work :S
*UPDATE: it seems that the .rpt keeps a history of the server names, and somehow doesn't seem to clear the list, so my friends computer "\sqlexpress" is still there, and I can't seem to clear it :S"
string nombre = WindowsIdentity.GetCurrent().Name.ToString().Split('\\')[1];
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables ;
//cryRpt.SetDatabaseLogon(string.Empty,string.Empty, nombre + "\\sqlexpress","trupp");
cryRpt.Load(FinalPath);
crConnectionInfo.ServerName = nombre + "\\sqlexpress";
crConnectionInfo.IntegratedSecurity = true;
crConnectionInfo.UserID = string.Empty;
crConnectionInfo.Password = string.Empty;
crConnectionInfo.DatabaseName = "trupp";
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
Upvotes: 1
Views: 2583
Reputation: 2103
You need to make a call to clear the existing connections from the report before setting the new ones.
cryRpt.Load(FinalPath);
// After loading report clear all datasourceconnections
cryRpt.DataSourceConnections.Clear();
// Now you can set new datasourceconnections
crConnectionInfo.ServerName = nombre + "\\sqlexpress";
Sometimes Crystal Reports can be a pain so if for some reason the above doesn't work you can always just set the server name on the existing connection embedded in the report.
cryRpt.DataSourceConnections[0].SetConnection(nombre + "\\sqlexpress", "trupp", true);
Upvotes: 3
Reputation: 108839
It's a pain in the neck, eh?
If you and your friends are using the same make and model of database table server, you might try putting an entry in each developer machine hosts file to create a local hostname alias, or if your development data bases are all on your own machines, use localhost.
If you use ODBC, you can all create your own ODBC entries with the same name and use those.
Upvotes: 0