当前位置:编程学习 > C#/ASP.NET >>

数据库链接的问题

我用的是VS2005和SQL2005Express
网站运行的在VS中运行的很正常,配置到IIS中的时候就会出现
无法打开登录所请求的数据库 "db_statInfo"。登录失败。
用户 'MICROSOF-2F5332\ASPNET' 登录失败。 
我只记得自己的用户名是'MICROSOF-2F5332\Administrator’后面不是ASPNET啊

然后我用把数据库登录选项选成Windows和SQL集成模式,新建了SQL账户sa1和密码,正常登录是可以进去,但是写进代码连VS都打不开数据库了

请问该怎么办啊,求助!!!
行 152:        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["db_statInfoConnectionString"].ToString());
行 153:        //打开数据库连接
行 154:        con.Open();
行 155:        //创建SqlCommand对象
行 156:        SqlCommand com = new SqlCommand(sql, con);
--------------------编程问答-------------------- 修改你的数据库连接字符串,使用sqlserver的登录名和密码,而不是windows验证  
在SQL Server中添加登录XX\ASPNET并给其相应数据库的权限 
 
--------------------编程问答-------------------- 速成版的sql没有运行,让它运行。 --------------------编程问答-------------------- 修改下你的web.config文件中的数据库链接字符串 --------------------编程问答-------------------- 配置文件 有问题吧,帖出来看看吧 --------------------编程问答--------------------
引用 4 楼 dotnetsong 的回复:
配置文件 有问题吧,帖出来看看吧

<configuration>
    <appSettings/>
      <connectionStrings>
        <add name="db_statInfoConnectionString" connectionString="Data Source=MICROSOF-2F5332\SQLEXPRESS;Initial Catalog=db_statInfo;Integrated Security=True"
         providerName="System.Data.SqlClient" />
        <!--<add name="db_statInfoConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=db_statInf;uid=sa1;pwd=mima123456" providerName="System.Data.SqlClient"//>-->
      </connectionStrings>
    <system.web>
        <!-- 
            设置 compilation debug="true" 将调试符号插入
            已编译的页面中。但由于这会 
            影响性能,因此只在开发过程中将此值 
            设置为 true。
        -->
       <compilation debug="true" />
        <!--
            通过 <authentication> 节可以配置 ASP.NET 使用的 
            安全身份验证模式,
            以标识传入的用户。 
        -->
        <authentication mode="Windows" />
        <!-- --------------------编程问答--------------------
引用 4 楼 dotnetsong 的回复:
配置文件 有问题吧,帖出来看看吧

<configuration>
  <appSettings/>
  <connectionStrings>
  <add name="db_statInfoConnectionString" connectionString="Data Source=MICROSOF-2F5332\SQLEXPRESS;Initial Catalog=db_statInfo;Integrated Security=True"
  providerName="System.Data.SqlClient" />
  <!--<add name="db_statInfoConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=db_statInf;uid=sa1;pwd=mima123456" providerName="System.Data.SqlClient"//>-->
  </connectionStrings>
  <system.web>
  <!--  
  设置 compilation debug="true" 将调试符号插入
  已编译的页面中。但由于这会  
  影响性能,因此只在开发过程中将此值  
  设置为 true。
  -->
  <compilation debug="true" />
  <!--
  通过 <authentication> 节可以配置 ASP.NET 使用的  
  安全身份验证模式,
  以标识传入的用户。  
  -->
  <authentication mode="Windows" />
  <!--
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,