使用 TCP/IP 连接到 SQL Server 2008

发布于 2024-08-24 18:28:27 字数 2738 浏览 3 评论 0 原文

当我尝试从 SQL Server Management Studio 使用 TCP/IP 连接时,出现以下错误。我需要一步一步的描述来解决我的问题。这是怎么回事?

Cannot connect to 
===================================

A network related or instance specific error when a connection to SQL Server...
(provider: Named pipe-provider, error: 40 -  SQL Server)
(.Net SqlClient Data Provider)

------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=53&LinkId=20476

------------------------------
Error Number: 53
Severity: 20
State: 0

------------------------------
Program Location:

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ObjectExplorer.ValidateConnection(UIConnectionInfo ci, IServerType server)
   at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser()

I get the following error when I try to connect with TCP/IP from SQL Server Management Studio. I need a step by step description to solve my problem. What's wrong here?

Cannot connect to 
===================================

A network related or instance specific error when a connection to SQL Server...
(provider: Named pipe-provider, error: 40 -  SQL Server)
(.Net SqlClient Data Provider)

------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=53&LinkId=20476

------------------------------
Error Number: 53
Severity: 20
State: 0

------------------------------
Program Location:

   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ObjectExplorer.ValidateConnection(UIConnectionInfo ci, IServerType server)
   at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

时光暖心i 2024-08-31 18:28:27

我经常忘记的是,即使您在 SQLServerNetwork->MSSQLServer 协议中将 tcp 标记为启用,您仍然需要为您的服务器启用可能不同的 IP 地址。即使只有一个 NIC 的服务器也会有多个 IP 地址。

  1. 单击上面列出的 MSSQLServer 协议。
  2. 然后在右侧窗格中启用 TCP/IP。
  3. 现在双击 TCP/IP 以获取对话框窗口。
  4. 如果要侦听服务器的所有 IP 地址,请在“是”中选择“是”
    第一个“协议”选项卡上的“全部监听”框;否则
  5. 选择“IP 地址”选项卡并通过设置“启用”来启用所需的 IP 地址
    是。

在此处输入图像描述

The thing I usually forget is that even if you mark tcp as enabled in SQLServerNetwork->Protocols for MSSQLServer, you still need to go and enable the potentially different IP addresses for your server. Even a server with a single NIC will have multipe IP addresses.

  1. Click on the Protocols for MSSQLServer as listed above.
  2. Then in the right hand pane enable TCP/IP.
  3. Now double click TCP/IP to get a dialog window.
  4. If you want to listen on all the IP addresses for the server Select Yes in the
    Listen All box on the first Protocol tab; otherwise
  5. Select the IP Addresses tab and enable the desired IP addresses by setting Enabled
    to Yes.

enter image description here

清风夜微凉 2024-08-31 18:28:27

当您检查 SQL Server 网络配置(开始菜单 > Microsoft SQL Server > 配置工具 > SQL Server 配置管理器 > SQL Server 网络配置)时,您会看到什么?

替代文本

您的服务器上真的启用了 TCP/IP 协议吗?它默认处于关闭状态,并且在大多数情况下保持关闭状态(除非您专门将其打开)。

仅使用基于 IP 的服务器地址并不意味着您正在使用 TCP/IP 协议进行连接......检查 http://www.connectionstrings.com/sql-server-2008 用于使用 TCP/IP 的示例连接字符串:

Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

关键是 Network Library=DBMSSOCN; 它告诉您的代码使用 TCP/IP 进行连接。

When you check the SQL Server Network Configuration (Start Menu > Microsoft SQL Server > Configuration Tools > SQL Server Configuration Manager > SQL Server Network Configuration), what do you see?

alt text

Is the TCP/IP protocol really enabled on your server? It's off by default, and stays off in most cases (unless you specifically turn it on).

Just using a IP-based server address doesn't mean you're connecting using the TCP/IP protocol.... check http://www.connectionstrings.com/sql-server-2008 for a sample connection string that will use TCP/IP:

Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

The key is the Network Library=DBMSSOCN; which tells your code to connect using TCP/IP.

场罚期间 2024-08-31 18:28:27

还值得检查 SQL Server 浏览器服务是否正在运行,因为 TCP/IP 连接将使用此服务

Also worth checking that the SQL Server Browser Service is running as TCP/IP connections will use this service

你丑哭了我 2024-08-31 18:28:27

请访问 www.connectionstrings.com。错误消息看起来您正在使用命名管道而不是 tcp/ip。不要忘记您必须在 SQL Server 的服务器计算机上显式启用 TCP/IP。

Have a look at www.connectionstrings.com. Error message looks like you're using named pipes and not tcp/ip. Don't forget you must enable TCP/IP on server machines for SQL Server explicitly.

假面具 2024-08-31 18:28:27

有一个很好的配置方法,包括

  • 为数据库服务器启用 TCP/IP 协议为
  • 数据库服务器启用远程连接
  • 允许 TCP 流量通过防火墙,网址

http://blogs.msdn.com/b/walzenbach /archive/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008.aspx

There is a good walkthrough for configuring this, including

  • Enabling TCP/IP protocol for the database server
  • Enabling remote connections for the database server
  • Allowing the TCP traffic through the firewall

at http://blogs.msdn.com/b/walzenbach/archive/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008.aspx.

山川志 2024-08-31 18:28:27

按照此操作:

开始
->节目
->微软 SQL Server 2008
->配置工具
-> SQL Server 配置管理器

SQL Server 网络配置
-> [SQLInstanceName] 的协议

右键单击​​ TCP/IP ->使能够

Follow this:

Start
-> Programs
-> Microsoft SQL Server 2008
-> Configuration Tools
-> SQL Server Configuration Manager

SQL Server network Configuration
-> Protocols for [SQLInstanceName]

Right click TCP/IP -> Enable

烟燃烟灭 2024-08-31 18:28:27

如果 TCP/IP 已启用,那么听起来您的防火墙正在阻止连接。打开相关端口应该就可以了。

您应该检查连接两端的防火墙。

If TCP/IP is already enabled then it sounds like your firewall is blocking the connection. Open the relevant ports and it should work.

You should check the firewall on both ends of the connection.

廻憶裏菂餘溫 2024-08-31 18:28:27

要使用"TCP/IP"连接到MSSQL(SQL Server),您需要使用SQL启用"TCP/IP"服务器配置管理器(SSCM)。这是如何查找 SQL Server 配置管理器(SSCM )在您的 Windows 计算机 中。

因此,在SSCM上,从“SQL Server Network Configuration/Protocols for SQLEXPRESS”启用“TCP/IP”,如下所示。 *默认情况下禁用MSSQL“TCP/IP”

在此处输入图像描述

点击“启用”后,如图所示上面,您将收到以下消息:

在此处输入图像描述

因此,如上面的消息所示,从“SQL Server 服务”重新启动 SQL Server(SQLEXPRESS) > 如下图:

在此处输入图像描述

最后,您可以使用“TCP/IP” 连接到MSSQL

To connect to MSSQL(SQL Server) with "TCP/IP", you need to enable "TCP/IP" with SQL Server Configuration Manager(SSCM). This is How to find SQL Server Configuration Manager(SSCM) in your Windows Machine.

So, on SSCM, enable "TCP/IP" from "SQL Server Network Configuration/Protocols for SQLEXPRESS" as shown below. *"TCP/IP" for MSSQL is disabled by default:

enter image description here

After clicking on "Enable" as shown above, you will get the message below:

enter image description here

So, as the message above says, restart SQL Server(SQLEXPRESS) from "SQL Server Services" as shown below:

enter image description here

Finally, you can connect to MSSQL with "TCP/IP".

触ぅ动初心 2024-08-31 18:28:27

并且 - 您可以在 SQL Server 配置管理器的协议屏幕中更改它,但只有重新启动 sql server 服务后才会生效。我只是重新启动 - 这是确定的唯一方法(那里有外星人参考:)

And - you can change it in the protocols screen of the SQL Server Configuration Manager but it won't take effect until the sql server service is restarted. I just reboot - it's the only way to be sure (Aliens reference there :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文