How to dynamically change crystal report database connection

▼魔方 西西 提交于 2020-01-22 15:11:23

问题


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.


回答1:


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);



回答2:


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);


来源:https://stackoverflow.com/questions/23470453/how-to-dynamically-change-crystal-report-database-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!