.Net ramblings
# Thursday, 27 July 2006
Crystal Reports: problems changing database connection at run time
i ran into a problem with my Crystal Reports.  instead of using the usual Typed Dataset approach, where you use Report.SetDataSource(DataSet), i decided that was too much hastle and it seems faster and simpler just to design the query in the Crystal Reports 'wizard', and then supply parameters and set the record filter appropriately.  what i didn't know was that it was insanely complicated to direct the report to a different database path at runtime (such as most users would have in their deployment environment, whether for Access or SQL server). 

i was using Report.SetDataBaseLogon("admin", "") etc and all sorts of variations but none of them were working.  I kept getting Logon Failed exceptions.  Apparently you need to iterate through each table used in the report and set the source database for each one.  Not only that, but neither of the following lines of code has any effect:
Report.Database.Tables[i].SetDataSource("admin", "", DbPath, "")
Report.Database.Tables[i].LogOnInfo.ConnectionInfo.ServerName = DbPath
apparently you have to create a TableLogOnInfo object and use ApplyLogOnInfo() with that on each table. 
here is what does work:
TableLogOnInfo t = new TableLogOnInfo();
t.ConnectionInfo.ServerName = dbPath;            
for(int i=0; i<rpt.Database.Tables.Count; i++)
    rpt.Database.Tables[i].ApplyLogOnInfo(t);


Thursday, 27 July 2006 16:31:47 (GMT Daylight Time, UTC+01:00)  #    Comments [3]  Asp.Net

Friday, 27 June 2008 14:15:15 (GMT Daylight Time, UTC+01:00)
Yup. and really it is very difficult. I have followed the procedure to set LoginInfo to each table object at runtime and it works
Perfectly on development machine but stops working on Production Machine.

I hate crystal reports when it behaves like this.

I am using visual studio 2008 and crystal reports 2008
Shadow
Friday, 27 June 2008 14:19:54 (GMT Daylight Time, UTC+01:00)
hi. i presume you have verified that the database schema is identical between the dev and production server? other than this i can't think why it wouldn't work. tim.
tim mackey
Wednesday, 11 March 2009 13:55:08 (GMT Standard Time, UTC+00:00)
I've got the same problem as shadow. Super irritating.
Nathan
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview