简体   繁体   English

如何从 Python + SQL Alchemy 连接到高可用性 SQL Server

[英]How to connect to a high availability SQL Server from Python + SQL Alchemy

Our infrastructure group has asked us to "add MultiSubnetFailover=True to all application connection strings" so that we can take advantage of a new SQL Server HA setup involving Availability Groups.我们的基础架构组要求我们“将 MultiSubnetFailover=True 添加到所有应用程序连接字符串”,以便我们可以利用涉及可用性组的新 SQL Server HA 设置。

I am stuck though since we have some python programs that connect (read+write) to the database via SQL Alchemy.我被卡住了,因为我们有一些 python 程序通过 SQL Alchemy 连接(读+写)到数据库。 I have been searching and I don't see anything about this MultiSubnetFailover feature being available as an option in SQL Alchemy or any other Python driver.我一直在搜索,但在 SQL Alchemy 或任何其他 Python 驱动程序中没有看到有关此 MultiSubnetFailover 功能可用作选项的任何信息。 Is it possible to connect to an HA setup utilizing the SQL Alchemy driver, or even Python, and if so how?是否可以使用 SQL Alchemy 驱动程序甚至 Python 连接到 HA 设置,如果可以,如何连接?

FYI - The link that my infrastructure guy pointed me to is here ( http://msdn.microsoft.com/en-us/library/hh205662%28v=vs.110%29.aspx ), and as you can see it is specifically about how .NET applications can utilize the "MultiSubnetFailover=True" setting in the connection string among other things.仅供参考 - 我的基础架构人员指向我的链接在这里( http://msdn.microsoft.com/en-us/library/hh205662%28v=vs.110%29.aspx ),正如你所看到的特别是关于 .NET 应用程序如何利用连接字符串中的“MultiSubnetFailover=True”设置等。

http://docs.sqlalchemy.org/en/latest/dialects/mssql.html#dialect-mssql-pyodbc-connect http://docs.sqlalchemy.org/en/latest/dialects/mssql.html#dialect-mssql-pyodbc-connect

You could use the example towards the end of the documentation's section like this:您可以在文档部分的末尾使用该示例,如下所示:

import urllib
from sqlalchemy import create_engine
connection_string = '127.0.0.1;Database=MyDatabase;MultiSubnetFailover=True'
engine_string = 'mssql+pyodbc:///?odbc_connect={}'.format(urllib.quote_plus(connection_string))
engine = create_engine(engine_string)

Update from comments从评论更新

For newer versions of Microsoft ODBC Driver for SQL Server, you may need to use MultiSubnetFailover=Yes instead of True对于更新版本的 Microsoft ODBC Driver for SQL Server,您可能需要使用MultiSubnetFailover=Yes而不是True

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM