4

我是新的水晶報表。我試圖通過使用報告嚮導visual studio 2012在我的win窗體c#應用程序中實現Crystal報告,所以不知道爲什麼會發生這種情況。在我的電腦上一切正常,但當我嘗試在另一臺計算機連接字符串更改並安裝時發生錯誤。如何動態更改水晶報表數據庫連接

我嘗試了很多鏈接,如Dynamic Connection string Change,但因爲我使用報告嚮導進行設置,所以不知道在哪裏使用這個。

我也嘗試了連接字符串的報告嚮導中的所有選項,但沒有發現任何在運行時更改連接字符串的選項。我可以attach connection String from app config at run time有任何選項。

回答

6

嘗試這樣:

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

剛一說明,我不得不指定'strServer'我的ODBC連接DNS的名稱。 – RubberDuck

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