ConfigurationManager keeps getting Machine.config connection string

前端 未结 4 2183
星月不相逢
星月不相逢 2020-12-16 20:56

I have a c# assembly that uses the app.config to store its database connection string. When debugging the application I noticed that the connection to the database kept fail

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 21:30

    When using connection strings in a DLL, you need to add them to your exe's app.config as well, using the exact same name for the setting. Then, you can change the connection string in the exe's .config file and the DLL will pick it up automatically when loaded.

    This is probably the only way you can have working custom connection strings in the app.config file when your DB persistence layer is implemented in a separate DLL. Don't even ask me how much time it took me to research and debug this.

提交回复
热议问题