简体   繁体   English

到SQL Server 2008的远程连接的连接字符串

[英]Connection String for Remote Connections to SQL Server 2008

I am trying to connect remotely to SQL Server 2008 R2 Express on a server running Windows Server 2008 R2. 我试图在运行Windows Server 2008 R2的服务器上远程连接到SQL Server 2008 R2 Express。 I receive the following error: 我收到以下错误:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. 建立与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. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) (提供者:TCP提供程序,错误:0-连接尝试失败,因为一段时间后连接方未正确响应,或者连接建立因连接主机未能响应而失败。)

I think the problem might be related to my connection string, because I am not sure exactly what it should be. 我认为问题可能与我的连接字符串有关,因为我不确定确切应该是什么。 I understand the connection string should take the form: 我了解连接字符串应采用以下形式:

Data Source=123.123.123.123\InstanceName;Initial Catalog=MyDBName;user id=MyUserName;password=MyPassword;

The instance name of my SQL Server installation takes the form ComputerName\\SQLEXPRESS . 我的SQL Server安装的实例名称采用ComputerName\\SQLEXPRESS的形式。 This is what I see when I log in to Management Studio on the server. 这是我在服务器上登录Management Studio时看到的。 So should the connection string begin with 所以连接字符串应该以

Data Source=123.123.123.123\ComputerName\SQLEXPRESS

This looks wrong because of all the slashes. 由于所有的斜线,这看起来是错误的。 I have tried to omit the computer name thus: 我试图这样省略计算机名称:

Data Source=123.123.123.123\SQLEXPRESS

I also read somewhere that you can specify a port so I have also tried 我还在某处读到可以指定端口的地方,所以我也尝试过

Data Source=123.123.123.123,1433\SQLEXPRESS

because I understand that 1433 is the TCP port used by SQL Server and 因为我知道1433是SQL Server使用的TCP端口,

Data Source=123.123.123.123,1434\SQLEXPRESS 

because I understand that 1434 is the UDP port used by SQL Server browser. 因为我知道1434是SQL Server浏览器使用的UDP端口。

I have also tried every combination of these and they all give the same error. 我也尝试了这些的每种组合,它们都给出相同的错误。

These are the steps I have taken to enable remote browsing on the server: 这些是我在服务器上启用远程浏览所采取的步骤:

  1. In Management Studio, right click the instance, go to Properties, Security and check SQL Server and Windows Authentication Mode. 在Management Studio中,右键单击实例,转到“属性”,“安全性”,然后检查“ SQL Server和Windows身份验证模式”。 On the connections tab I have checked "Allow remote connections to this computer". 在连接选项卡上,我已选中“允许远程连接到这台计算机”。

  2. In SQL Server Configuration Manager I have enabled all four connection options (Shared Memory, Named Pipes, TCPIP and Via) under every node they occur. 在SQL Server配置管理器中,我已在它们出现的每个节点下启用了所有四个连接选项(共享内存,命名管道,TCPIP和通过)。 Under protocols for SQL Express I have tried specifying port 1433 and also leaving it blank with TCP Dynamic Ports set to 0 (which I think is meant to enable dynamic ports). 在用于SQL Express的协议下,我尝试指定端口1433,并将TCP动态端口设置为0(我认为是为了启用动态端口)而将其留空。

  3. I have created firewall exceptions for TCP Port 1433, UDP Port 1434, and program exceptions for sqlservr.exe and sqlbrowser.exe . 我为TCP端口1433,UDP端口1434创建了防火墙例外,并为sqlservr.exesqlbrowser.exe程序例外。

If someone could tell me which of the four versions of the DataSource part of the connection string I should be using it would be a great help, even if it did not solve the problem. 如果有人可以告诉我我应该使用连接字符串的DataSource部分的四个版本中的哪个版本,那将是很大的帮助,即使它不能解决问题。 It would mean that everything I try subsequently I would only have to test once instead of four times. 这意味着我随后尝试的所有内容仅需测试一次,而不是四次。

Thanks in advance for any help! 在此先感谢您的帮助!

Where did you enter the firewall exceptions, on your machine, on the server, or both? 您在计算机,服务器或两者上的哪里输入了防火墙例外?

The second connection string is the only really valid one. 第二个连接字符串是唯一真正有效的字符串。 Can you telnet to the server on port 1433? 您可以通过端口1433 telnet到服务器吗? Can you connect to the instance from Management Studio remotely and the problem is only from your code where the connection string is? 您能否从Management Studio远程连接到实例,而问题仅出自连接字符串所在的代码? Did you try running the same code on the server? 您是否尝试在服务器上运行相同的代码? Did you try forcing TCP/IP (vs. named pipes/shared memory etc) adding the following parameter to your connection string: 您是否尝试强制将TCP / IP(与命名管道/共享内存等相比)添加以下参数到连接字符串中:

Network=DBMSSOCN;

This question comes up quite a lot and I'm sure you're hitting something that others have hit before. 这个问题很多,我敢肯定,您遇到的是其他人以前遇到的问题。 Have you gone through this article, " How to troubleshoot connecting to the SQL Server Database Engine "? 您是否浏览过本文“ 如何解决对SQL Server数据库引擎的连接故障 ”? Also there are 20+ questions on here that mention this error message and Express, according to this search result . 根据搜索结果 ,这里还有20多个问题提到了此错误消息和Express。 I suggest double-checking your settings against some of the items in those answers that solved the issue for other users. 建议您针对那些为其他用户解决了该问题的答案中的某些项目仔细检查您的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM