ConfigurationManager keeps getting Machine.config connection string

前端 未结 4 2165
星月不相逢
星月不相逢 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条回答
  •  借酒劲吻你
    2020-12-16 21:37

    Try getting an instance of your app.config file as a Configuration object:

    var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    
    var myConnString = config.ConnectionStrings["VersionConnectionString"].ConnectionString;
    

    This bypasses the machine config file completely.

提交回复
热议问题