How to dynamically change crystal report database

2020-06-20 10:48发布

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.

2条回答
家丑人穷心不美
2楼-- · 2020-06-20 11:02
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);
查看更多
forever°为你锁心
3楼-- · 2020-06-20 11:07

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);
查看更多
登录 后发表回答