故障转移后如何连接到镜像SQL Server?

Vim*_*987 6 sql-server ado.net failover connection-string high-availability

我设置了一个数据库镜像,然后使用它connectionstring连接到它:

    Data Source={0};Failover Partner={1};Initial Catalog=AdventureWorks;
    Integrated Security=True;
Run Code Online (Sandbox Code Playgroud)

将一些数据添加到数据库后,我关闭了主服务器,因此镜像服务器成为主服务器.我再次打开连接,得到这个错误:

    System.Data.SqlClient.SqlException: A transport-level error has 
occurred when sending the request to the server. (provider: Shared Memory 
Provider, error: 0 - No process is on the other end of the pipe.)
Run Code Online (Sandbox Code Playgroud)

我认为通过连接字符串中指定的故障转移伙伴,ADO.NET将为我完成工作.那我现在该怎么办?

这个问题很紧迫.非常感谢你的帮助.

Vim*_*987 4

幸运的是,我解决了这个问题。我需要做的就是调用 ClearPool 方法:

SqlConnection.ClearPool(conn);
Run Code Online (Sandbox Code Playgroud)

该方法将清除连接池。然后,问题就消失了。我很高兴。

谢谢大家的支持。:D