有时无法与 SQL 服务器建立连接

Sometimes can't establish connection to SQL Server

我们在 Microsoft Access 2000 中有一个应用程序(抱歉,没办法)连接到 SQL Server 2008 R2 Express,它没有任何连接问题。我们的应用程序使用 .NET ActiveX 控件,它必须连接到相同的 SQL 服务器。有时有效,有时无效。如果没有,我会收到以下错误消息:

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: SQL Network Interfaces, error 26: - Error Locating Server/Instance Specified)

好像和防火墙有关。当我在 SQL 服务器为 运行 的服务器上关闭 Windows 防火墙时,仅针对 "Domain network settings",并立即再次打开它,部分问题得到解决时间(几个小时)。

看来系统管理员找到了答案。他检查了防火墙日志文件,发现端口号 1434 被 UDP 协议阻止,所以他不得不在防火墙设置中打开它。

Port 1434 is used by the SQL Browser Service which allows connections to named instances of SQL Server that use dynamic ports with out having to know what port each named instance is using, especially since this can change between restarts of the named instance. [link]

如果您在家工作(例如本地 Windows 7、8.1、10 台计算机),并尝试连接到远程数据库(通过 SQL 服务器数据库引擎,使用 SSMS)以下很可能是您想要的...

转到Windows 防火墙: 首先,创建一个新的 OUTBOUND 规则,select "port" 和 "allow" TCP 端口 1433。 然后,创建一个新的 OUTBOUND 规则,select "port" 和 "allow" UDP 端口 1434。 最后,找到您的 SSMS 的路径。 (例如,右键单击 SSMS 快捷方式,转到属性,找到 "target" 路径,然后复制它。 然后,新建一个OUTBOUND Rule,select程序,粘贴你复制的路径,允许

就是这样。

注意:如果您实际上是在物理服务器或托管数据库的虚拟机上,则应遵循相同的步骤,但要创建 INBOUND 规则。

希望这对您有所帮助,对我有帮助。 :-)