2010-12-16 63 views
0

我正在檢索連接字符串基於cookie.Now中存儲的值 我在做水晶報告。我無法硬編碼服務器憑證。我必須從web.config的連接字符串中獲取這些證書。所以我可以將這些憑據傳遞給我的水晶報告。 請幫忙急。從連接字符串檢索服務器名稱和數據庫的水晶報告asp.net web.config

ConnectionInfo reportConnectionInfo = new ConnectionInfo(); 
reportConnectionInfo.ServerName = connection string server name from web.config 
reportConnectionInfo.DatabaseName = connection string database name from web.config 
reportConnectionInfo.UserID = ...; 
reportConnectionInfo.Password = ...; 

回答

0

你可以做這樣的事情:

ConnectionInfo reportConnectionInfo = new ConnectionInfo(); 
reportConnectionInfo.ServerName = WebConfigurationManager.AppSettings["ServerName"]; 
reportConnectionInfo.DatabaseName = WebConfigurationManager.AppSettings["DatabaseName"]; 
reportConnectionInfo.UserID = WebConfigurationManager.AppSettings["UserID"]; 
reportConnectionInfo.Password = WebConfigurationManager.AppSettings["Password"]; 

你也可以提供連接字符串是在web.config

string connectionString = WebConfigurationManager.ConnectionStrings["MyConnectionString"]; 
+0

有在web.config中的多個連接字符串我正在基於cookie值檢索。 – 2010-12-16 08:15:18

+0

任何想法?????? – 2010-12-16 08:34:20

+0

每個連接字符串都有一個不同的名字,我猜?所以用這個名字來找回正確的名字。 – Scoregraphic 2010-12-16 09:05:43

相關問題