我需要這樣的東西:鑄造誤差ConnectionStringSettingsCollection
Configuration cf = ConfigurationManager.OpenExeConfiguration("name_of.exe");
ConnectionStringSettingsCollection s = cf.ConnectionStrings;
但是,這給出了一個錯誤:
Cannot implicitly convert type 'ConnectionStringsSection' to 'ConnectionStringsSectionCollection'
當我這樣做:
ConnectionStringSettingsCollection s = ConfigurationManager.ConnectionStrings;
沒有錯誤,但我需要第一個,因爲我沒有使用默認的配置文件。 那麼爲什麼在第一種情況下(而不是在第二種情況下)轉換失敗?
編輯: 對不起,但與'第一'我第一代碼示例,而不是第一個連接字符串。由於某些原因,第二個代碼示例沒有將connectionsStrings轉換爲ConnectionsStringSettingsCollection,但第一個代碼示例沒有,那是我的問題。
所以我不得不做的事:「ConnectionStringSettingsCollection S = cf.ConnectionStrings.ConnectionStrings! – Ruud