Sql-Server

我可以使用 sqlcmd 通過命名管道連接到伺服器,但供應商工具正在獲取命名管道提供程序,錯誤:40

  • August 16, 2011

我在我的工作站上執行了一個 Windows 服務,它是供應商提供的連接到數據庫的工具的一部分。它不會啟動錯誤我在事件日誌中收到 4 個錯誤,其中包含以下內部異常:

Inner Exception
---------------
Type : System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : A network-related or instance-specific error occurred while establishing a connection to 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. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Source : .Net SqlClient Data Provider
Help link : 
Errors : System.Data.SqlClient.SqlErrorCollection
Class : 20
LineNumber : 0
Number : 53
Procedure : 
Server : 
State : 0
ErrorCode : -2146232060
Data : System.Collections.ListDictionaryInternal
TargetSite : Void OnError(System.Data.SqlClient.SqlException, Boolean)
Stack Trace :    at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
  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 System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)

當然要注意的關鍵是**(提供者:命名管道提供者,錯誤:40 - 無法打開與 SQL Server 的連接)**

但是,如果我這樣做,runas /user:serviceuser cmd我可以通過命名管道連接到伺服器就好了:

C:\Windows\system32>sqlcmd -S np:\\%%SERVER_NAME%%\pipe\sql\query
1> SELECT @@servername, db_name()
2> go




--------------------------------------------------------------------------------
------------------------------------------------ -------------------------------
--------------------------------------------------------------------------------
-----------------
SERVER_NAME
                                            master



(1 rows affected)

我還需要採取哪些其他故障排除步驟?

檢查 Ring Buffers 輸出是否存在連接錯誤,如果您看到 Login Failed 錯誤消息,還要檢查錯誤日誌。檢查該工具正在使用的登錄名,看看您是否可以使用相同的登錄名登錄到 SQL 實例。還要找出他們提供的伺服器名稱,看看他們是否使用了別名。

引用自:https://serverfault.com/questions/301693