app.config を使用してデータベース接続文字列を格納する ac# アセンブリがあります。アプリケーションをデバッグしているときに、ConfigurationManager が machine.config 接続文字列を返し続けたため、データベースへの接続が失敗し続けていることに気付きました。
データソース=.\SQLEXPRESS; 統合セキュリティ;....
<clear/
app.config の接続文字列の前に >を追加すると、開発マシンの問題が修正されました。本番環境にデプロイしたときに問題が再発しました。machine.config 接続文字列の使用を停止する方法を誰か教えてもらえますか?
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[0].ConnectionString);
<connectionStrings>
<clear/>
<add name="VersionConnectionString"
connectionString=" Data Source=localhost;Initial Catalog=VersionInfo;User ID=user;Password=password"
providerName="System.Data.SqlClient" />
</connectionStrings>
アップデート
以下でも machine.config 接続文字列が表示されますか?!
Configuration appConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
string dllConfigData =
appConfig.ConnectionStrings.ConnectionStrings[0].ConnectionString;