Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 636
Hot Cool Stud Avatar asked May 05 '14 10:05

Hot Cool Stud


2 Answers

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);
like image 113
Aishwarya Shiva Avatar answered Nov 15 '22 08:11

Aishwarya Shiva


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

//may be you need to set the integrated security to false, first.
report.DataSourceConnections[o].IntegratedSecurity = False;

report.DataSourceConnections[0].SetConnection(strServer, strDatabase, strUserID, strPwd);
like image 22
Solomon Hailemolocot Avatar answered Nov 15 '22 09:11

Solomon Hailemolocot