In C# , how can I read a connection string stored in my web.config file connection string?
In C# class library, how can I read a connection string stored in my web.config file connection string tag? As in:
<connectionStrings>
<add name="CLessConStringLocal" connectionString="server=localhost;database=myDb;uid=sa;pwd=mypass开发者_开发技巧word;"/>
</connectionStrings>
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.
精彩评论