2010-03-05 110 views
10

當我嘗試從SQL Server Management Studio連接TCP/IP時出現以下錯誤。我需要一步一步的描述來解決我的問題。這裏有什麼問題?使用TCP/IP連接到SQL Server 2008

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() 
+9

只是一個友好的建議:不要求任何東西,即當你說「我想要一步一步描述解決我的問題。 ..「。它給人錯誤的印象;我們都是志願者。 – 2010-03-05 16:01:11

+0

好的,對不起......我的意思聽起來像那樣...... – MCOL 2010-03-05 16:04:25

+0

很可能,您的客戶端或服務器(或兩者)都沒有設置爲允許tcp/ip作爲您的Sql Server傳輸。 – RBarryYoung 2010-03-05 16:18:20

回答

4

查看www.connectionstrings.com。錯誤消息看起來像你使用命名管道而不是tcp/ip。不要忘記,您必須明確地在SQL Server的服務器機器上啓用TCP/IP。

+0

Thanks..but我正在使用tcp/ip號碼 – MCOL 2010-03-05 16:04:58

+0

如果您將服務器設置爲不使用默認端口,則可能需要添加別名或明確聲明端口。作爲示例,這應該在發佈的URL上。除此之外,防火牆和連接字符串上的給定註釋應該導致解決方案。 – Sascha 2010-03-09 14:16:41

2

您是否200%確定您的服務器已設置爲接受通過TCP/IP的連接?

+0

是的,我確定..... – MCOL 2010-03-05 16:19:34

+0

在您嘗試連接到的服務器上,運行SQL Server配置管理器,網絡配置,檢查TCP/IP是否啓用(與上述相關)。同時檢查IP地址列表(通過雙擊)以確保您嘗試連接到其中的一個。 – CResults 2010-03-05 16:33:45

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; 

關鍵是​​它告訴您的代碼使用TCP/IP連接。

+1

TCP/IP已啓用... – MCOL 2010-03-05 17:33:14

+0

在服務器和客戶端?客戶端協議的順序是什麼?除非您明確指定使用哪一個,否則SQL Server客戶端將選擇列表中第一個啓用的。這是在「SQL本機客戶端配置」 – 2010-03-05 18:24:43

0

關注這個:

開始 - >程序 - >微軟SQL Server 2008的 - >配置工具 - > SQL Server配置管理器

SQL Server網絡配置 - >協議[SQLInstanceName ]

右鍵單擊TCP/IP - >啓用

+1

完成..但它不工作..... – MCOL 2010-03-05 17:31:57

0

如果TCP/IP爲alre那麼這聽起來像你的防火牆阻止了連接。打開相關的端口,它應該工作。

您應該檢查連接兩端的防火牆。

17

我通常會忘記的是,即使您將SQLServerNetwork-> Protocols中的tcp標記爲啓用了MSSQLServer,您仍然需要爲您的服務器啓用可能不同的IP地址。即使只有一個NIC的服務器也會有多個IP地址。

  1. 點擊上面列出的MSSQLServer協議。
  2. 然後在右側窗格中啓用TCP/IP。
  3. 現在雙擊TCP/IP來獲得對話窗口。
  4. 如果要偵聽服務器的所有IP地址在第一個協議選項卡的 全部偵聽框中選擇是;否則
  5. 選擇IP地址選項卡並通過將啓用 設置爲是來啓用所需的IP地址。

enter image description here

+0

如果有人有興趣如何從腳本執行它:http://promikro.com.pl/2013/09/18/mssql2012expr-en-ip-addrs-problem/ – SOReader 2014-07-12 19:11:46

8

另外值得一檢查SQL Server瀏覽器服務正在運行的TCP/IP連接將使用這項服務

+1

這是爲我做了什麼。我也同時打開了「SQL Server Agent」。非常感謝這個建議。 – DustinA 2013-11-05 05:01:23

-1

而且 - 你可以在SQL Server配置的協議屏幕改變管理器,但它將不會生效,直到SQL Server服務重新啓動。我只是重新啓動 - 這是唯一可以肯定的方式(外星人蔘考:)