Hot Cool Stud Hot Cool Stud - 1 year ago 101
C# Question

How to dynamically change crystal report database connection

I am new with crystal reports. I tried to to implement the crystal report in my win form c# application using report wizard visual studio 2012, so don't know what happen's in backhand for this. Everything works good on my computer but when i tried install this on another computer connection string changes and gives error.

I tried many links like Dynamic Connection string Change but as i am using report wizard for setup so don't know where to use this.

I also tried all options in report wizard for connection string but didn't find anything that change connection string at run time.

Is there any options by which i can

attach connection String from app config at run time

Answer Source

Try something like this:

strServer= ConfigurationManager.AppSettings["ServerName"].ToString();
strDatabase= ConfigurationManager.AppSettings["DataBaseName"].ToString();
strUserID= ConfigurationManager.AppSettings["UserId"].ToString();
strPwd= ConfigurationManager.AppSettings["Password"].ToString();

report.DataSourceConnections[0].SetConnection(strServer, strDatabase, strUserID, strPwd);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download