使用 Azure Sql 故障转移组时连接字符串应该是什么?

What should the connection string be when using Azure Sql Failover groups?

好的,所以我在 mydatabase.databsae.windows.net 设置了一个 Azure Sql 故障转移组,其中包含 2 个服务器:

我去 connectionstrings.com 获取我的 Sql Azure 连接字符串,如下所示:

Server=tcp:mydatabase.database.windows.net;Database=mySqlDatabase; User ID=MyUser@[serverName];Password=myPassword;Trusted_Connection=False; Encrypt=True;

现在问题出在User ID=MyUser@[serverName] 我试过了:

User ID=MyUser@mydatabase 但这没有用,并重复 returns 错误:

Database 'mySqlDatabase' on server 'mydatabase' is not currently available. Please retry the connection later

我也试过 User ID=MyUser@mydatabase1 并且 确实 有效。

但是连接字符串中的上述问题是,当我故障转移到 mydatabase2 时,我需要去更新我所有的连接字符串。

那么使用 Sql 故障转移组时正确的连接字符串是什么?

尝试:

Server=tcp:mydatabase.database.windows.net;Database=mySqlDatabase;
User ID=MyUser@mydatabase;Password=myPassword;Trusted_Connection=False;
Encrypt=True;MultiSubnetFailover=True;

这是故障转移组的当前限制:

Note: If at this point you go to SSMS and try to connect to your Primary/Secondary database using above listeners, you will receive error and will not be able to login. Ideally it should have allowed, but it currently fails, as it tries to connect to the Master database which is currently not part of the group. This is currently being worked upon and should be resolved soon. Till then, workaround is to provide the database name while connecting to server. Use the option button to provide database name.

这意味着目前只有以下连接字符串可以工作:

Server=tcp:mydatabase.database.windows.net;Database=mySqlDatabase;
User ID=MyUser@mydatabase1;Password=myPassword;Trusted_Connection=False;
Encrypt=True;

Server=tcp:mydatabase.database.windows.net;Database=mySqlDatabase;
User ID=MyUser@mydatabase2;Password=myPassword;Trusted_Connection=False;
Encrypt=True;

不幸的是,这会导致自动故障转移完全失效,因为您需要重新配置所有连接字符串

参考:https://social.technet.microsoft.com/wiki/contents/articles/37968.working-with-azure-sql-auto-failover-group.aspx