Server Error in '/' Application.
--------------------------------------------------------------------------------A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  Stack Trace: 
[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4844759
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +4858065
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +90
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +376
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
   System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +29
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +4861516
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
   System.Data.SqlClient.SqlConnection.Open() +122
   AutoManagerM1.WebForm2.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\桌面\华亭煤矿管理系统\AutoManagerM1\AutoManagerM1\Image.aspx.cs:25
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627 
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053 

解决方案 »

  1.   

    我的连接字符串:Data Source=192.168.0.251;Initial Catalog=AutoManageM2;Persist Security Info=True;User ID=sa;Pooling=False;Password=lonber
      

  2.   

    而且在IIS发布的那台电脑爆出的错误是:provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server、
    别的电脑访问爆出的错误是:
    Runtime Error 
    Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
    <!-- Web.Config Configuration File --><configuration>
        <system.web>
            <customErrors mode="Off"/>
        </system.web>
    </configuration>
     Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
    <!-- Web.Config Configuration File --><configuration>
        <system.web>
            <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
        </system.web>
    </configuration>
     
      

  3.   

    SQL Server 2005 不允许远程连接解决方法做课程设计时,很多学生都遇到这个问题。把解决方法写在这儿,供参考。刚刚安装的数据库系统,按照默认安装的话,很可能在进行远程连接时报错,通常是错误:"在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接) "搜MSDN,上面有一片机器翻译的文章,是在让人难以明白,现在总结如下:明白了SQL Server是个网络数据库就可迎刃而解了,简单的分为下面的集中情况。1. 数据库引擎没有启动。有两种启动方式:(1)开始->程序->Microsoft SQL Server 2005->SQL Server 2005外围应用配置器,在打开的界面单击"服务的连接的外围应用配置器",在打开的界面中找到Database Engine,单击"服务",在右侧查看是否已启动,如果没有启动可单击"启动",并确保"启动类型"为自动,不要为手动,否则下次开机时又要手动启动;(2)可打开:开始->程序->Microsoft SQL Server 2005->配置工具->SQL Server Configuration Manager,选中SQL Server 2005服务中SQL Server(MSSQLSERVER) ,并单击工具栏中的"启动服务"按钮把服务状态改为启动;使用上面两种方式时,有时候在启动的时候可能会出现错误,不能启动,这时就要查看"SQL Server 2005配置管理器"中的SQL Server 2005网络配置->MSSQLSERVER协议中的VIA是否已启用,如果已启用,则把它禁止.然后再执行上述一种方式操作就可以了.2. 是否已经允许远程连接。这个部分可以简单的分为4个方面,分别是在 SQL Server上启用远程连接、启用SQL Server 浏览服务、在Windows 防火墙中为SQL Server 2005 创建例外和在Windows 防火墙中为“SQLBrowser”创建例外。下面是几个具体的操作方式,摘自MSDN,个人觉得文章的黑体部分应当特别的一起我们的注意。
    在SQLServer 实例上启用远程连接
    1.指向“开始->程序->Microsoft SQL Server 2005->配置工具->SQL Server 外围应用配置器”
    2.在“SQL Server 2005 外围应用配置器”页, 单击“服务和连接的外围应用配置器”
    3.然后单击展开“数据库引擎”, 选中“远程连接”,在右边选中“本地连接和远程连接”,
    再选择要使用的协议,( 这个地方应当启用TCP/IP 和命名管道服务!)单击“应用”,您会看到下消息:
    “直到重新启动数据库引擎服务后,对连接设置所做的更改才会生效。”,单击“确定”按钮返回
    4.展开“数据库引擎”, 选中“服务”,在右边单击“停止”,等到 MSSQLSERVER 服务停止,
    然后单击“启动”,重新启动MSSQLSERVER 服务。启用 SQLServer 浏览器服务
    1.指向“开始->程序->Microsoft SQL Server 2005->配置工具->SQL Server 外围应用配置器”
    2.在“SQL Server 2005 外围应用配置器”页, 单击“服务和连接的外围应用配置器”
    3.然后单击展开“SQL Server Browser”, 选中“服务”,在右边“启动类型”选择“自动”,
    再单击“启动”,单击“确定”按钮返回在Windows 防火墙中为“SQL Server 2005”创建例外
    1.在 Windows 防火墙设置界面中,选择“ 例外” 选项卡,然后单击“添加程序”
    2.在“添加程序窗口”中单击“浏览”
    3.然后找到“C:\ProgramFiles\Microsoft Files\Microsoft SQL Server\ MSSQL.1 \MSSQL\Binn\sqlservr.exe”,
    单击“确定”返回
    注意 : 路径可能会根据 SQL Server 2005 安装不同而不同。 MSSQL.1 是占位符,对应数据库实例ID。
    4.对每个需要打开远程访问的SQL Server 2005 实例,重复步骤 1 至 3。在Windows 防火墙中为“SQLBrowser”创建例外
    1.在 Windows 防火墙设置界面中,选择“ 例外” 选项卡,然后单击“添加程序”
    2.在“添加程序窗口”中单击“浏览”
    3.然后找到“C:\ProgramFiles\Microsoft Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe”,
    单击“确定”返回
    注意 : 路径可能会根据 SQL Server 2005 安装不同而不同
    那就数据库引擎没有启动!
    到管理工具点击服务查看sql server是否启动
      

  4.   

    参见
    http://support.microsoft.com/kb/914277/zh-cn
    如何配置 SQL Server 2005 以允许远程连接