Fetching connection string from appconfig file in c#

前端 未结 10 1016
隐瞒了意图╮
隐瞒了意图╮ 2020-12-19 07:39

I have the following connection string declared in my app.config file:

  
    

        
10条回答
  •  长情又很酷
    2020-12-19 08:10

    First, you must add the appSettings tag

     
        
          
        
      
    

    Second, add a reference to System.Configuration to your project and insert a using System.Configuration in the source.

    Then, you can use ConfigurationManager.AppSettings to access your config setting:

    string result = ConfigurationSettings.AppSettings["SqlConnectionString"];
    

提交回复
热议问题