Skip to content Skip to sidebar Skip to footer

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 A

Solution 1:

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

Post a Comment for "How To Connect To A High Availability Sql Server From Python + Sql Alchemy"