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

System.Data.SqlClient.SqlException

 System.Data.SqlClient.SqlException: 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)
--------------------编程问答--------------------  检查你的连接字符串.
--------------------编程问答-------------------- 这种错误通常都是数据库连接字符串写得有问题,贴出你的Webconfig文件来看看! --------------------编程问答-------------------- 检查了,没问题 --------------------编程问答-------------------- <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings/>
<system.web>
<!--  --------------------编程问答--------------------
引用 4 楼 wocaishiqiao 的回复:
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="fal……

如果这是你的源码的话,很不幸你根本就没写连接数据库的代码。

<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings>
  <add key="Mycon" value="Data Source=.\SQLEXPRESS;Initial Catalog=数据库名;User ID=sa;pwd=你的密码" />
<appSettions>
<connectionStrings/>
<system.web> --------------------编程问答-------------------- <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings>
<add key="Mycon" value="Data Source=.\SQLEXPRESS;Initial Catalog=数据库名;User ID=sa;pwd=你的密码" />
</appSettions>
<connectionStrings/>
<system.web> --------------------编程问答-------------------- 你是怎么实现你的字符串连接,如果你是在webconfig里面写的话推荐使用6楼的方法,如果你在DAL层写的话 private SqlConnection conn;
        public SqlConnection Conn
        {
            get
            {
                if (conn == null)
                    conn = new SqlConnection("server=.;database=myOA;uid=sa;pwd=123456");
                return conn;
            }
        }检查你的连接字符是否打开,或者说你的SQL服务是否打开了 --------------------编程问答-------------------- 感谢各位朋友,问题已解决,谢taomanman
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,