我的工作站上运行着一个 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)
我还需要采取哪些其他故障排除步骤?
答案1
检查 Ring Buffers 输出中的连接错误,如果看到“登录失败”错误消息,还请检查错误日志。检查该工具正在使用的登录名,看看是否可以使用相同的登录名登录 SQL 实例。还要找出他们提供的服务器名称,看看他们是否使用了别名。