我刚刚在我的家庭服务器上安装了SQL Server Express 2012。我试图从桌面PC的Visual Studio 2012连接到它,并反复得到众所周知的错误:

在建立与SQL Server的连接时,发生了与网络相关或特定于实例的错误。未找到服务器或无法访问服务器。验证实例名称是否正确,SQL Server是否配置为允许远程连接。(提供商:Named Pipes提供商,错误:40 -无法打开到SQL Server的连接)

为了解决这个问题,我所做的是:

在服务器上运行“SQL Server配置管理器”,启用“SQL Server浏览器” 在服务器上为本地子网的TCP端口1433和1434添加Windows防火墙例外。 验证我在桌面上登录的用户在SQL Server实例上进行了登录。 验证我在SQL Server实例上使用Windows身份验证。 反复重启SQL Server和整个服务器。 把我的头发都拔出来。

如何让SQL Server 2012 Express允许远程连接!?


很高兴我问了。我最终找到的解决办法是:

如何配置SQL Server Express以允许端口1433上的远程tcp/ip连接?

运行SQL Server配置管理器。 进入“SQL Server网络配置> SQLEXPRESS协议”。 确保TCP/IP已启用。

到目前为止,一切顺利,完全在意料之中。但之后:

右键单击TCP/IP并选择属性。 验证在IP2下,IP地址被设置为计算机在本地子网上的IP地址。 向下滚动到IPAll。 确保“TCP动态端口”为空。(我的端口设置为5位数。) 确保“TCP端口”设置为“1433”。(我的是空白。)

(此外,如果您遵循这些步骤,就不需要启用SQL Server浏览器,只需要允许端口1433,而不是1434。)

这额外的五个步骤是我在以前版本的SQL Server、Express或其他版本中从未做过的。它们似乎是必要的,因为我在服务器上使用了一个命名实例(myservername\SQLEXPRESS),而不是默认实例。在这里看到的:

配置服务器监听特定的TCP端口(SQL Server配置管理器)

你也可以设置

只听“不”

在协议对话框中输入IP地址IP1(比如)

set enabled为Yes, 定义你的IP地址 “TCP动态”设置为“空白” TCP端口到1433(或其他端口)

在我安装的SQL Server 2012开发者版,安装默认设置,我只需要加载SQL Server配置管理器-> SQL Server网络配置-> MSSQLSERVER协议,并将TCP/IP从禁用更改为启用。

您所需要做的就是打开服务器防火墙上的相关端口。

我有一个不同的问题,所有的答案到目前为止提到!

我应该首先说,我有它在Visual Studio,而不是SQL Server Express,但解决方案应该完全相同。

天啊,这其实很简单,也许还有点傻。 当我试图创建一个数据库,Visual Studio建议SQL Server的名称,它给了我我的Windows用户名,因为它实际上是服务器的名称,我去了。

实际上是我的Windows用户名+ \SQLEXPRESS。如果你没有改变任何设置,这可能也是你的。如果有效,停止阅读;这就是我的答案。如果不起作用,可能名字不同。

如果像我一样,你在Visual Studio中只遇到了这个问题,请执行以下步骤:

打开SQL Server Management studio。 如果你没有看到你的服务器(默认停靠在左边)按F8或转到视图->对象资源管理器。 右键单击服务器名称并选择Properties(最后一项) 在左下角,你可以看到你的服务器的实际名称在“服务器”下面(不是连接,而是上面)。

这是服务器的名称,这是您应该尝试连接的对象!不是Visual Studio建议的!

你可以用这个来解决这个问题:

进入START > EXECUTE,运行cliiconfg . exe。

Named Pipes协议将在列表中排在第一位。降级,推广TCP/IP。

彻底测试应用程序。

我希望这对你有所帮助。

连接到远程SQL Server的正确方法(不打开UDP端口1434并启用SQL Server浏览器)是使用ip和端口而不是命名实例。

使用ip和port代替命名实例也更安全,因为它减少了攻击表面积。

也许2张图就能表达2000个单词…

该方法使用指定的端口(这是大多数人想要的,我相信)..

此方法需要打开UDP端口1434和SQL Server浏览器运行..

这篇文章帮助我……

如何在SQL Server中启用远程连接

SQL Server中的一切都配置好了,我的问题是防火墙阻塞端口1433

我更喜欢“Rosdi Kasim”的方式,因为它不需要在IP上进行详细配置。

当我再次尝试启动另一个服务器时,我肯定会再次忘记它。

通过简单地启用Sql Server浏览器服务,然后在连接服务器时在IP后面添加\SQLEXPRESS来保持简单(KISS)。

直接使用IP而不使用“\SQLEXPRESS”是我的失败点,因为它不使用默认端口。

谢谢。

还有一件事…

Kyralessa提供了很好的信息,但我还有一件事要补充,即使在这篇文章之后,我也被难住了。

在“SQL Server Network Configuration > Protocols for Server > TCP/IP Enabled”下。右键单击TCP/IP,选择属性。在IP地址下,您需要为正在使用的每种连接类型将启用设置为Yes。

还要检查的一件事是,已命名实例的拼写是否正确!

本文在排除连接问题时非常有用:如何排除连接到SQL Server数据库引擎的故障

我必须添加一个防火墙入站端口规则来打开UDP端口1434。这是一个Sql Server浏览器监听。

我必须通过配置管理器添加端口,并在我的sql连接[host]\[db实例名]中添加端口号,1433

注意instancename和port之间的,(逗号)

我最近遇到了这个问题。2015年8月

通过打开SQL Server配置管理器解决

SQL Server网络配置-> SQLEXPRESS的协议 “TCP/IP -> IP地址”页签 一切保持默认值,只设置IPALL: TCP端口为1433

可以与SQL Server Manager连接到机器:[hostaddress], 1433

例子:

在我的例子中,数据库运行在非标准端口上。检查您正在连接的端口是否与运行数据库的端口相同。如果存在多个SQL server实例,请检查正确的实例。

I had the same issue with SQL Server 2014 locally installed named instance. Connecting using the FQDN\InstanceName would fail, while connecting using only my hostname\InstanceName worked. For example: connecting using mycomputername\sql2014 worked, but using mycomputername.mydomain.org\sql2014 did not. DNS resolved correctly, TCP/IP was enabled within SQL Configuration Manager, Windows Firewall rules added (and then turned the firewall off for testing to ensure it wasn't blocking anything), but none of those fixed the problem.

最后,我不得不在SQL Server上启动“SQL Server浏览器”服务,这解决了连接问题。

我从未意识到SQL Server浏览器服务实际上是在帮助SQL Server建立连接;我的印象是,当你点击“浏览更多”服务器连接时,它只是帮助填充下拉列表,但它实际上有助于将客户端请求与正确的端口#对齐,如果端口#没有显式分配(类似于网站绑定如何帮助缓解托管多个网站的IIS web服务器上的相同问题)。

这个连接项给了我关于SQLServer浏览器服务的线索:https://connect.microsoft.com/SQLServer/feedback/details/589901/unable-to-connect-on-localhost-using-fqdn-machine-name

when you use wstst05\sqlexpress as a server name, the client code separates the machine name from the instance name and the wstst05 is compared against the netbios name. I see no problem for them to match and the connection is considered local. From there, we retrieve the needed information WITHOUT contacting SQL Browser and connect to the SQL instance via Shared Memory without any problem. when you use wstst05.capatest.local\sqlexpress, the client code fails the comparison of the name (wstst05.capatest.local) to the netbios name (wstst05) and considers the connection "remote". This is by design and we will definitely consider improving this in the future. Anyway, due to considering the connection remote and the fact that it is a named instance, client decides that it needs to use SQLBrowser for name resolution. It attempts to contact SQL Browser on wstst05.capatest.local (UDP port 1434) and apparently that part fails. Hence the error you get.

来自TechNet的“SQL Server Browser”服务的原因(重点是我添加的):https://technet.microsoft.com/en-us/library/ms181087(v=sql.120).aspx

在“使用SQL Server浏览器”部分:

If the SQL Server Browser service is not running, you are still able to connect to SQL Server if you provide the correct port number or named pipe. For instance, you can connect to the default instance of SQL Server with TCP/IP if it is running on port 1433. However, if the SQL Server Browser service is not running, the following connections do not work: Any component that tries to connect to a named instance without fully specifying all the parameters (such as the TCP/IP port or named pipe). Any component that generates or passes server\instance information that could later be used by other components to reconnect. Connecting to a named instance without providing the port number or pipe. DAC to a named instance or the default instance if not using TCP/IP port 1433. The OLAP redirector service. Enumerating servers in SQL Server Management Studio, Enterprise Manager, or Query Analyzer. If you are using SQL Server in a client-server scenario (for example, when your application is accessing SQL Server across a network), if you stop or disable the SQL Server Browser service, you must assign a specific port number to each instance and write your client application code to always use that port number. This approach has the following problems: You must update and maintain client application code to ensure it is connecting to the proper port. The port you choose for each instance may be used by another service or application on the server, causing the instance of SQL Server to be unavailable.

更多信息来自同一篇文章的“SQL Server浏览器如何工作”部分:

Because only one instance of SQL Server can use a port or pipe, different port numbers and pipe names are assigned for named instances, including SQL Server Express. By default, when enabled, both named instances and SQL Server Express are configured to use dynamic ports, that is, an available port is assigned when SQL Server starts. If you want, a specific port can be assigned to an instance of SQL Server. When connecting, clients can specify a specific port; but if the port is dynamically assigned, the port number can change anytime SQL Server is restarted, so the correct port number is unknown to the client. ... When SQL Server clients request SQL Server resources, the client network library sends a UDP message to the server using port 1434. SQL Server Browser responds with the TCP/IP port or named pipe of the requested instance. The network library on the client application then completes the connection by sending a request to the server using the port or named pipe of the desired instance

连接SQL Server有问题?

尝试断开防火墙。

如果你可以在防火墙断开的情况下连接,可能是你错过了一些输入规则,比如“sql service broker”,将这些输入规则添加到你的防火墙中:

“sql admin connection”TCP端口1434

“sql admin connection”udp端口1434

“sql analysis service”TCP端口2383

" sql browse analysis service " TCP端口2382

“sql调试器/ rpc”TCP端口135

“SQL SERVER”TCP端口1433和其他如果你有动态端口

“sql service broker”TCP端口4022