数据库连接 失败: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
错误:在Microsoft SQL本土客户:发生错误,而建立一个到服务器的连接。 When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. 当连接到SQL Server 2005中,这样的失败 可能造成的事实,即根据默认设置SQL Server不允许远程连接。 Or, 或,An error has occurred while establishing a connection to the server. 发生了错误,而建立一个到服务器的连接。 When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. 当连接到SQL Server 2005中,这样的失败 可能造成的事实,即根据默认设置SQL Server不允许远程连接。 (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 2) (提供者:命名管道提供商,错误: 40 -无法打开连接到S QLS erver) ( M icrosoftS QLS erver,错误: 2 )
错误原因及解决方法:
一、确保SQL Server 2005的配置是否正确,允许传入的连接上的实例数据库服务器,否则,使把对本地和远程连接设置。
- 单击开始按钮,然后到程序或所有程序,然后选择了Microsoft SQL Server 2005 ,其次是配置工具 。 点 击和运行SQL Server表面积配置 。
- 关于“ SQL Server 2005的 表面积配置”页上,单击 表面积的配置服务和连接 。
- 关于“表 面积的配置服务和连接”页上,扩大数据库引擎的 树中,单击远程连接 。
- 选择本地和远程连接 ,或本地 连接只 ,其中只适用于如果没有远程系统会尝试连接到SQL Server ,有用时,你刚才尝试连接和验 证与服务器安装完毕后。
- 选择适当的议 定书,使本地和/或远程连接的环境。 以确保最高的相容性,选择使用TCP / IP和命名管道 。
- 点击应用 按钮时,做了。
- 单击确定 按钮时,提示讯息,他说: “更改连接设置将不会生效,直到您 重新启动数据库引擎的服务” 。
- 关于“表面 积的配置服务和连接”页上,扩大资料库引擎 ,然后单击服务 。
- 点击停止 按钮来停止SQL Server服务。
- 等到MSSQLServer服务站,然后单击开 始 按钮,重新启动MSSQLServer服务。
二、web.config文 件中的数据库连接串中的主机IP或数据库名及服务名错误!!
将其错误修正,错误解决!!(本人遇到的是第二种情况,此情况应特别注意 )