ConfigurationManager keeps getting Machine.config connection string

前端 未结 4 2158
星月不相逢
星月不相逢 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:40

    You should be getting your connection string by NAME instead of INDEX - that will ensure you're getting what you're asking for.

    Try

    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["VersionConnectionString"].ConnectionString);
    

提交回复
热议问题