我正在尝试使用sqlalchemy引擎将属性MultiSubnetFailover传递给连接字符串。虽然将参数传递给pyodbc非常流畅,但pymssql拒绝接受连接字符串中的任何参数。
这失败
attributes = "?driver=ODBC+Driver+17+for+sql+server"
engine = create_engine(
'mssql+pymssql://' +
"username" + ':' +
"password" + '@' +
"127.0.0.1" + "/" +
"databaseName" + attributes)
错误
Traceback (most recent call last):
File "C:/Users/ChaitanyaB/PycharmProjects/Test/TestUpdate.py", line 35, in <module>
(TblServices.OrganizationId == '72A229D4-186B-4B0E-A98F-7DB5DB3566DB')
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\orm\query.py", line 2423, in all
return list(self)
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\orm\query.py", line 2571, in __iter__
return self._execute_and_instances(context)
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\orm\query.py", line 2584, in _execute_and_instances
close_with_result=True)
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\orm\query.py", line 2575, in _connection_from_session
**kw)
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\orm\session.py", line 893, in connection
execution_options=execution_options)
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\orm\session.py", line 898, in _connection_for_bind
engine, execution_options)
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\orm\session.py", line 334, in _connection_for_bind
conn = bind.contextual_connect()
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\engine\base.py", line 2039, in contextual_connect
self._wrap_pool_connect(self.pool.connect, None),
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\engine\base.py", line 2074, in _wrap_pool_connect
return fn()
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\pool.py", line 376, in connect
return _ConnectionFairy._checkout(self)
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\pool.py", line 713, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\pool.py", line 480, in checkout
rec = pool._do_get()
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\pool.py", line 1060, in _do_get
self._dec_overflow()
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\util\langhelpers.py", line 60, in __exit__
compat.reraise(exc_type, exc_value, exc_tb)
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\pool.py", line 1057, in _do_get
return self._create_connection()
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\pool.py", line 323, in _create_connection
return _ConnectionRecord(self)
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\pool.py", line 449, in __init__
self.connection = self.__connect()
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\pool.py", line 607, in __connect
connection = self.__pool._invoke_creator(self)
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\engine\strategies.py", line 97, in connect
return dialect.connect(*cargs, **cparams)
File "C:\Users\ChaitanyaB\NewVirtualEnvironment\lib\site-packages\sqlalchemy\engine\default.py", line 385, in connect
return self.dbapi.connect(*cargs, **cparams)
File "pymssql.pyx", line 578, in pymssql.connect (pymssql.c:9754)
TypeError: connect() got an unexpected keyword argument 'MultiSubnetFailover'
虽然我可以使用属性=&#34;&#34;
此外,与pyodbc相同的连接字符串
attributes = "?driver=ODBC+Driver+17+for+sql+server"
engine = create_engine(
'mssql+pyodbc://' +
"username" + ':' +
"password" + '@' +
"127.0.0.1" + "/" +
"databaseName" + attributes)
我想知道在使用pymssql时是否有不同的方法来传递连接属性。任何帮助表示赞赏。