【问题标题】:C# Application can't connect to mirroring SQL Server after manually failover手动故障转移后 C# 应用程序无法连接到镜像 SQL Server
【发布时间】:2015-11-05 08:44:55
【问题描述】:

我设置了镜像数据库(计算机名:SQL-Prim、SQL-Mirr,域名:sql-1.ooo.org、sql-2.ooo.org)。 我没有AD,我用公共IP地址和域名配置它们。 我编写了一个 C# 应用程序来测试故障转移行为。 连接字符串是这样的:

data source=sql-1.ooo.org;Failover Partner=sql-2.ooo.org;initial catalog=TestDB;User Id={0};Password={1};App=EntityFramework

C#应用程序是不断更新数据:

while (true)
{
  try
  {
    using (TestEntities context = new TestEntities())
    {
      //update data
    }
  }
  catch (Exception ex)
  {
    //log error
  }
  System.Threading.Thread.Sleep(1000); //sleep for a while
}

一开始,应用程序连接到 SQL-Prim 并运行良好。 当我手动从 SQL-Prim 故障转移到 SQL-Mirr 时,应用程序抛出异常:

"The underlying provider failed on Open."

如果我重新启动应用程序,它会连接到 SQL-Mirror 并运行良好。然后,我再次手动从 SQL-Mirr 故障转移到 SQL-Prim。该应用程序一直运行良好。如果我手动从 SQL-Prim 故障转移到 SQL-Mirr,应用程序会再次抛出相同的异常。

我尝试将 SQL-Mirr 的 IP 地址添加到测试应用程序计算机上的“C:\Windows\System32\drivers\etc\host”。 应用程序运行良好。我可以任意对 2 个 DB 进行故障转移而不会出现任何错误。

我对这个问题感到困惑。 有没有办法避免更改主机文件? 感谢您的帮助。

【问题讨论】:

    标签: c# sql-server database-mirroring


    【解决方案1】:

    您需要在 DTC 配置中启用“允许远程客户端”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-21
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多