`

sqlserver2012外部无法连接的解决办法

 
阅读更多

http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/


SQL SERVER – FIX : ERROR : (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error:)

Regular readers of my blog are aware of the fact that I have written about this subject umpteen times earlier, and every time I have spoken about a new issue related to it.Few daysago, I had redone my local home network. I haveLAN setupwith wireless router connected with my four computers, two mobile devices, one printer and one VOIP solution. I had also formatted my primary computer and clean installed SQL Server 2008 into it. Yesterday, incidentally, I was sitting in my yard trying to connect SQL Server located inhome officeand suddenly I stumbled upon the following error. Finding the solution was the most infuriating part as it consumed my precious 10 minutes.

Let us look atfewof the common errors received:

An error has occurred while establishing a connection to the server.

(provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 5)

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 Server, Error: 1326)

I eventually found the resolution to this error on this blog itself; so I was saved from hunting for the solution. I am sure there are a number of developers who had previously fixed this error while installing SQL Server 2008 or SQL Server 2005 but in due course forgot the right solution to this error.This is just a quick refresher. Make sure to bookmark this as you never know when you would need this solution.

Let us check into the steps to resolve this error.

1)SQL Server should be up and running.

Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> SQL Server Services, and check if SQL Server service status is “Running”.

In addition, ensure that your remote server is in the same network. Run “sqlcmd-L” in your command prompt to ascertain if your server is included in your network list. You can even findtutorialfor the same hereSQL SERVER – Find All Servers From Local Network – Using sqlcmd – Detect Installed SQL Server on Network.

I have confronted numerous situations when these nerve-wracking errors crop up, and most of the time when I try to troubleshoot I notice that SQL Server services are neither running nor installed. If SQL Server is not installed as default instance SQL Server Browser should be running together with it; we will explore this further in Topic 5.

2) Enable TCP/IP in SQL Server Configuration

When two or more SQL Servers are connected acrossnetworkthey do all communication using TCP/IP. The default port of SQL Server installation is 1433. This port can be changed throughSQL Server Configuration Manager. TCP/IP should be enabled for SQL Server to be connected.

Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> Select TCP/IP

Right Click on TCP/IP >> Click on Enable

You must restart SQL Server Services for all the changes to take effect. Right click and go to menu properties to selectlocationwhere default port of SQL Server can be changed.

3) Open Port in Windows Firewall

Windows Firewall is very efficacious in protecting the Operating system from all sorts of malicious attacks. By default, many of the ports and services are refrained from running byfirewall. Time and again, SQL Server ports are not open in firewall as well. All the ports on which SQL Server is running should be added toexceptionand firewall should filter all the traffic from those ports. As described, by default SQL Server runs on port 1433, but ifdefault portis changed then the new port should be added toexception. If SQL Server has named instance (another instance besides default instance) is installed,SQL Server browsershould also be added to the exception, as described in Step 7.

Go to Control Panel >> Windows Firewall >> Change Settings >> Exceptions >> Add Port

Make the following entries in popup “Add a Port” and click OK.
Name : SQL
Port Number: 1433
Protocol: Select TCP

4) Enable Remote Connection

Enabling remote connection is another important, yet oft-neglected step that is frequently missed by database administrators while setting up SQL Server. If this feature is turned off SQL Server will function smoothly onlocal machine, but it will let another server connect to it remotely. By default this feature is ON in SQL Server 2008.

Right click on the server node and select Properties.

Go to Left Tab of Connections and check “Allow remote connections to this server”

5) Enable SQL Server Browser Service

If SQL Server is not installed as default instance but instead installed as named instance and also if there is no specific TCP/IP port configured, it will give rise to the error that is being discussed in this article. If SQL Server Browser service is enabled, it will allow the server to be connected through dynamic TCP/IP port. Enabling this service is a one-time process, as on enabling it once it will apply to all the instances installed on the same server.

Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> SQL Server Browser

Right Click on SQL Server Browser >> Click on Enable

6) Create exception of sqlbrowser.exe in Firewall

As elucidated in Step 6,sqlbrowserservice needs to be enabled fornamedinstance. Windows Firewall may prevent sqlbrowser.exe to execute. So, it is imperative to addexceptionfor the same in windows firewall.

Search for sqlbrowser.exe on your local drive where SQL Server is installed. Copy the path of the sqlbrowser.exe like C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe and create the exception of the file in Firewall, as delineated inStep 3.

7) Recreate Alias

It is getting quite common to createaliasof SQL Server and use it inapplication. This will ensure that in future if any physical SQL Server has to be moved, it will not be required to change any code or connection string. You can simply createaliaswith the same name pointing to different SQL Server and it will start working instantaneously. I have observed that a couple of times due to internal error while recreating alias this error was fixed.

Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Native Client 10.0 Configuration >> Aliases

Delete the alias thatis givingproblem and recreate it with identical parameters.

I have tried my best to include all the methods of fixing this error and if I have missed any, please leave a comment and I will be very glad to include them here. I have put in my effort to encompass this issue in one article that needs to be refereed when any connection error comes up.

分享到:
评论

相关推荐

    SQL SERVER连接oracle数据库几种方法

    SQL SERVER 连接 Oracle 数据库几种方法 在实际开发中,我们经常需要在 SQL Server 中连接 Oracle 数据库,以便实现数据交换和集成。那么,如何在 SQL Server 中连接 Oracle 数据库呢?下面我们将介绍几种常见的...

    Knight's Microsoft SQL Server 2012

    ### Knight’s Microsoft SQL Server 2012 Integration Services 24-Hour Trainer #### 概述 本教材《Knight’s Microsoft SQL Server 2012 Integration Services 24-Hour Trainer》旨在为读者提供全面而深入的学习...

    sqlserver修改端口

    使用SQL Server Management Studio (SSMS) 或其他数据库管理工具尝试连接到SQL Server,确认端口更改成功。在连接属性中输入新的服务器名称(包括端口号,如 "localhost,2433" 或 "yourserver.com,2433")和凭据,...

    测试与SQL Server 2005数据库的连接

    防火墙可能阻止外部连接,需要设置规则允许指定端口(默认是1433)的入站流量。同时,确保SQL Server服务正在运行,并且配置为允许远程连接。 5. **检查身份验证模式**: SQL Server支持Windows身份验证和SQL ...

    sqlserver2019中文帮助(带书签,高清)

    SQL Server 2019是Microsoft推出的一款关系型数据库管理系统,具有强大的数据处理能力和高度的安全性。本中文帮助文档提供了全面的指引,涵盖了从安装、配置到管理和优化的各个环节。 在【新增功能】部分,SQL ...

    sqlserver无主键表的同步方案1

    其次,对于字段长度超过8000的字段,如image、text、ntext,脚本通过将它们转换为varbinary(max)、varchar(max)、nvarchar(max)来尝试解决,但在SQL Server 2012及更高版本中,实际最大长度仍受限于8000,这可能导致...

    用myEclipse连接数据库sqlServer所需要的jar包

    标题中的"用myEclipse连接数据库sqlServer所需要的jar包"指的是在MyEclipse中开发Java应用并连接到SQL Server数据库时需要的特定库。MyEclipse是基于Eclipse的一个扩展,它支持多种数据库连接,包括SQL Server。为了...

    Sql server 存儲過程技巧

    解决办法是在关键字两边加上方括号: ```sql SELECT * FROM users WHERE [level] = 1 ``` **最佳实践**: - 编写存储过程时,应尽可能地对所有可能与系统关键字冲突的标识符使用方括号包围,以确保在不同版本间移植...

    JDBC连接SQL2005解决办法

    ### JDBC连接SQL Server 2005 解决办法详解 #### 一、下载与安装驱动程序 为了确保能够成功地通过Java Database Connectivity (JDBC) 连接到SQL Server 2005数据库,首要步骤是下载合适的驱动程序。根据描述中的...

    SQL Server 2008管理员必备指南(超高清PDF)Part3

    无论您是学生还是数据库领域的从业人员,都可从《SQL Server 2008管理员必备指南》获得解决问题和完成工作所需的信息。 《SQL Server 2008管理员必备指南》重要主题: 规划、部署和配置SQL Server 2008 管理服务器,...

    sql server 错误代码大全

    ### SQL Server 错误代码详解 SQL Server 是一款广泛使用的数据库管理系统,在运行过程中可能会遇到各种错误情况。了解这些错误代码及其含义对于及时诊断并解决问题至关重要。以下是对部分常见错误代码的详细解读:...

    SQL Server 2008管理员必备指南(超高清PDF)Part1

    无论您是学生还是数据库领域的从业人员,都可从《SQL Server 2008管理员必备指南》获得解决问题和完成工作所需的信息。 《SQL Server 2008管理员必备指南》重要主题: 规划、部署和配置SQL Server 2008 管理服务器,...

    SQL Server 2008管理员必备指南(超高清PDF)Part2

    无论您是学生还是数据库领域的从业人员,都可从《SQL Server 2008管理员必备指南》获得解决问题和完成工作所需的信息。 《SQL Server 2008管理员必备指南》重要主题: 规划、部署和配置SQL Server 2008 管理服务器,...

    C++连接sqlserver及Excel导出小工具

    标题 "C++连接sqlserver及Excel导出小工具" 描述了使用C++编程语言实现的一个小型应用程序,其核心功能是连接到SQL Server数据库并能够将数据导出为Excel格式的表格,同时还包括了制作雷达图的功能。这个工具对于...

    双机热备Sqlserver

    双机热备Sqlserver是一种高可用性解决方案,用于确保数据库服务在一台服务器出现故障时能够无缝切换到另一台服务器,从而最小化业务中断。在本文中,我们将详细探讨如何配置和实现基于Windows 2008和Sql Server 2008...

    SQL Server 2005 ETL专家系列-05 SQL Server 2005 Integration Service的高级应用

    10. **与外部系统集成**:学习如何通过SSIS连接到各种数据源,如文本文件、Excel工作簿、Oracle数据库或其他SQL Server实例。 本课程旨在提升你对SSIS的高级特性和实用技巧的理解,帮助你成为能解决复杂ETL挑战的...

    sqlserver服务.txt

    ### SQL Server 2005 TCP/IP 连接配置与启用方法 在处理SQL Server 2005的相关问题时,经常会遇到无法通过网络访问数据库的情况。这种情况通常是由TCP/IP连接被禁用所导致的。本文将详细介绍如何检查并启用SQL ...

    SQL Server 2008高级程序设计 4/6

    SQL Server 2008高级程序设计 4/6 SQL Server 2008 2010 高级程序设计 作者:(美)维埃拉 著,杨华,腾灵灵 译 出版社:清华大学 出版日期:2010-4-1 ISBN:9787302222729 字数:1250000 页码:730 ----------------...

    SQL SERVER网络连接技术.pdf

    综上所述,文件内容涉及了SQL SERVER网络连接技术的多个关键知识点,包括网络连接的应用场景、服务器端与客户端网络连接的特点和配置方法、故障排除步骤、API接口集与网络组件的作用,以及安全性考虑和网络库文件的...

    在Eclipse中用JDBC连接Sql Server 2005总结.doc

    在Eclipse中使用JDBC连接到...以上就是使用Eclipse通过JDBC连接到SQL Server 2005的完整过程,包括所有可能出现的问题及解决方法。希望这对你的开发工作有所帮助。在实际操作中,根据自己的环境和需求进行适当的调整。

Global site tag (gtag.js) - Google Analytics