如何在配置文件中写数据库连接语句?
我用bs三层结构架构系统,用.net 开发,请问如何在配置文件中写数据库连接,写一个就可以在data层调用!请大家帮帮忙 !
------解决方案-------------------- <connectionStrings>
<add name= "DatabaseConnection "
connectionString= "Data Source=(local);Initial
Catalog=Northwind;Integrated Security=SSPI; "
KeyRestrictions= "Encrypt=;Packet Size=; "
KeyRestrictionBehavior= "AllowOnly " />
</connectionStrings>
------解决方案-------------------- <appSettings> 节点下:
<add key= "strConnection " value= "server=192.168.0.20;database=IMS;user id=sa;password=123456; " />
引用:public static readonly string connString = System.Configuration.ConfigurationSettings.AppSettings[ "strConnection "];
------解决方案--------------------WebConfigurationManager.ConnectionStrings
使用的时候这样使用就可以了
或者用GetSection