SQL 服务器故障转移:找不到网络路径 - 直到重启后

SQL Server Failover: The network path was not found - until after reboot

我在我们的环境中遇到问题,在该环境中有 2 个 SQL 服务器处于故障转移配置中。因此,如果一个不可用,另一个就会接管。

现在这些服务器时不时地切换角色,所以一台服务器从主服务器到从服务器再变回来。

每当发生这种情况时,我们都会遇到一些 SQL 错误,现在我的印象是 .NET 框架应该能够处理这种情况,但是现在还不是那么重要,如果我们可以从中恢复。

但似乎我们现在遇到了这样一种情况,他们进行了切换,我们的 WebAPI 应用程序只是拒绝恢复并且一直出现错误。

但是,如果我们重新启动应用程序池,事情似乎会恢复正常。

每个 SqlConnection 对象总是在使用后被释放,并且它们是用提供故障转移伙伴的连接字符串创建的:

Data Source=Server_1.Domain; Initial Catalog=database_name;User ID=db_user;Password=user_pass;Failover Partner=Server_2.Domain

如果重要的话,服务器和应用程序位于不同的域中。

现在,如果这只是在他们切换角色时持续存在,那就没问题了,但我不太明白为什么它会持续存在。

我可以在 Whosebug 上找到无数关于这个问题的线程,但它们似乎都在一致的状态下存在问题,而这并不那么一致。

所以所有常用的"Allow remote connections"、启用"TCP/IP"、打开的端口等都应该是有序的,否则我们应该根本无法连接。

看到"Named Pipes Provider, error: 40"我也有点疑惑,不是同一台机器不应该用TCP/IP吗? o.O...

以下是更多错误详细信息。


[Win32Exception (0x80004005): The network path was not found]

[SqlException (0x80131904): 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)]
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +642
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +116
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +1079
   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +6600667
   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +233
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +278
   System.Data.SqlClient.SqlConnection.Open() +239

我希望有人可能以前见过类似的东西并能提供一两个提示?

我们从来没有真正破解过这个。甚至没有 SQL 服务器顾问。 相反,他向我们指出了一个不同的方向,即可用性组。

由于我们不能马上这样做,现在我们为 SQL 服务器使用 DNS 别名,如果主服务器出现故障,我们将别名切换为指向另一台。这不是自动发生的,但至少在切换 DNS 的情况下不会发生上述错误。