I need some help.
Actually, I've read about this problem, and I thought that I've resolved it, but it keeps bothering me.
It's about different logins at developing and production enviroment.
This was supposed to be solution (EF and SQL Server):
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder((model.Connection as EntityConnection).StoreConnection.ConnectionString);
ConnectionInfo ci = new ConnectionInfo();
ci.ServerName = builder.DataSource;
ci.DatabaseName = builder.InitialCatalog;
ci.UserID = builder.UserID;
ci.Password = builder.Password;
report.SetDatabaseLogon(ci.UserID, ci.Password, builder.DataSource, ci.DatabaseName);
foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in report.Database.Tables)
{
TableLogOnInfo logon = tbl.LogOnInfo;
logon.ConnectionInfo = ci;
tbl.ApplyLogOnInfo(logon);
}
I extract login information from Entity Connection and apply it to all the tables in report. That should do the trick. I added SetDatabaseLogon() only to be sure, but that's not required.
Now, when I run report in production enviroment, report pops up a Database login screen showing CORRECT server name (production server), NOTHING next to database (that is my concern), proper username, and no password, asking to type in login information.
I type it in, but CR says "Login failed. Please try again". I mean WTF. I use the very same credential to connect to database with Management Studio.
I am using WPF viewer, BTW.
I am really stuck here, I've done some debugging, and connection info gets all the right data, so it must be report who is the culprit, but what should I do?
Any help would be appreciated. I hope somebody has stumbled to a same problem before me.
Regards
I had a problem with using "SetDatabaseLogon"
I changed by
report.DataSourceConnections[0].SetConnection("Servername","InitialCatalog", "UserID", "Password");
I hope this will helpful to someone.
Looking at the code on my Blog Post that does the same jobs, I can see a few differences:
tbl.Location
to itself (this might be re initializing something internally - it didn't work without it). report.SetDatabaseLogon
Other than that they're basically identical.
Code:
void SetConnection(ReportDocument rd, crConnectionInfo ci)
{
foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in rd.Database.Tables)
{
TableLogOnInfo logon = tbl.LogOnInfo;
logon.ConnectionInfo = ci;
tbl.ApplyLogOnInfo(logon);
tbl.Location = tbl.Location;
}
if (!rd.IsSubReport) {
foreach {ReportDocument sd in rd.SubReports) {
SetConnection(sd,ci)
}
}
}
(Note: Just hand coded this, so check it before you use it).
This works on the VS2008 version of crystal reports (forget what it was called).
EDIT: One other thing, in my connection initialization, there are a couple of extra properties set:
ci.Type = ConnectionInfoType.SQL;
ci.IntegratedSecurity = false;
It was totally stupid problem, and i solved it by chance. Installation of Crystal Reports on my desktop computer was crooked or something, so whenever I edited something with database expert (add some tables, for example), it spoiled my report. All I did is use "set database location" option on my laptop, and now my reports run flawlessly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.