使用TCP/IP连接到SQL Server 2008

MCO*_*COL 10 sql-server database-connection sql-server-2008

当我尝试从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()
Run Code Online (Sandbox Code Playgroud)

Ed *_*Ost 17

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

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

在此输入图像描述


mar*_*c_s 13

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

alt text http://i50.tinypic.com/5lpcpk.png

您的服务器上是否真的启用了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;
Run Code Online (Sandbox Code Playgroud)

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


Iso*_*age 8

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


Sas*_*cha 4

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