web.config中配置数据库连接字符串

1.使用windows身份验证连接数据库

  

<connectionStrings>

        <add name="ConnStrToSQL" connectionString="Data Source=MYWORLD\SQLEXPRESS2005;Initial Catalog=Myworld;Integrated Security=SSPI;" providerName="SqlServer"/>

    </connectionStrings>

2.使用SQL SERVER身份验证登陆

<connectionStrings>

    <add name="ConnStrToSql" connectionString="server=.;database=myworld;uid=sa;pwd=123"/>

  </connectionStrings>

数据访问中使用web.config中配置好的连接字符串

在项目“引用”下面邮件添加引用,.net栏中选择System.Configuration

using System.Configuration;
.......
    .....
private static string ConnStr = ConfigurationManager.ConnectionStrings["ConnStrToSQL"].ConnectionString;

    .....

你可能感兴趣的:(config)