开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜