In C# , how can I read a connection string stored in my web.config file connection string?

前端 未结 1 465
孤街浪徒
孤街浪徒 2020-12-19 02:52

In C# class library, how can I read a connection string stored in my web.config file connection string tag? As in:


 

        
1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-19 03:49

    Use ConfigurationManager.ConnectionStrings collection to access the connection stings that stored in your configuration files.

    For example :

    string myConnectionString = ConfigurationManager
              .ConnectionStrings["CLessConStringLocal"].ConnectionString;
    

    Note : Do not forget to reference to System.Configuration assembly.

    0 讨论(0)
提交回复
热议问题