【问题标题】:Connect to SQL Server 2008 with TCP/IP使用 TCP/IP 连接到 SQL Server 2008
【发布时间】:2011-01-24 04:30:22
【问题描述】:

当我尝试从 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()

【问题讨论】:

  • 只是一个友好的建议:不要要求任何东西,即当你说“我想要一步一步的描述来解决我的问题......”时。它给人以错误的印象;我们都是志愿者。
  • 好吧,抱歉……我的意思不是这样的……
  • 很可能,您的客户端或服务器(或两者)都没有设置为允许 tcp/ip 作为 Sql Server 传输。
  • 遇到同样的问题.. 在这里尝试了所有答案。防火墙没有阻止它并在配置管理器中启用了 tcp。

标签: sql-server sql-server-2008 database-connection


【解决方案1】:

当您检查 SQL Server 网络配置 (Start Menu > Microsoft SQL Server > Configuration Tools > SQL Server Configuration Manager > SQL Server Network Configuration) 时,您看到了什么?

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

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

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

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

【讨论】:

  • 在服务器端和客户端??客户端协议的顺序是什么?除非您明确指定要使用哪个,否则 SQL Server 客户端将选择列表中第一个启用的。那在“SQL Native Client 配置”下
【解决方案2】:

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

【讨论】:

  • 谢谢..但我使用的是 tcp/ip 号码
  • 如果您将服务器设置为不使用默认端口,您可能需要添加别名或明确说明端口。这应该以发布的 URL 为例。除此之外,防火墙和连接字符串上的给定 cmets 应该会导致解决方案。
【解决方案3】:

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

【讨论】:

    【解决方案4】:

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

    【讨论】:

    • 这就是为我做的。我还同时打开了“SQL Server Agent”。非常感谢这个建议。
    【解决方案5】:

    我通常忘记的是,即使您在 SQLServerNetwork->Protocols for MSSQLServer 中将 tcp 标记为启用,您仍然需要为您的服务器启用可能不同的 IP 地址。即使是具有单个 NIC 的服务器也将具有多个 IP 地址。

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

    【讨论】:

    【解决方案6】:

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

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

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

    【讨论】:

      【解决方案7】:

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

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

      【讨论】:

        【解决方案8】:

        按照这个:

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

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

        右键单击 TCP/IP -> 启用

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2010-12-10
          • 1970-01-01
          • 2011-07-17
          • 2010-10-22
          • 2013-06-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多