--- /dev/null
+.. change::
+ :tags: bug, mssql
+ :tickets: 5592
+
+ Fixed issue where a SQLAlchemy connection URI for Azure DW with
+ ``authentication=ActiveDirectoryIntegrated`` (and no username+password)
+ was not constructing the ODBC connection string in a way that was
+ acceptable to the Azure DW instance.
user = keys.pop("user", None)
if user:
connectors.append("UID=%s" % user)
- connectors.append("PWD=%s" % keys.pop("password", ""))
+ pwd = keys.pop("password", "")
+ if pwd:
+ connectors.append("PWD=%s" % pwd)
else:
- connectors.append("Trusted_Connection=Yes")
+ authentication = keys.pop("authentication", None)
+ if authentication:
+ connectors.append("Authentication=%s" % authentication)
+ else:
+ connectors.append("Trusted_Connection=Yes")
# if set to 'Yes', the ODBC layer will try to automagically
# convert textual data from your database encoding to your
Other keywords interpreted by the Pyodbc dialect to be passed to
``pyodbc.connect()`` in both the DSN and hostname cases include:
-``odbc_autotranslate``, ``ansi``, ``unicode_results``, ``autocommit``.
+``odbc_autotranslate``, ``ansi``, ``unicode_results``, ``autocommit``,
+``authentication`` (e.g., ``authentication=ActiveDirectoryIntegrated``).
Note that in order for the dialect to recognize these keywords
(including the ``driver`` keyword above) they must be all lowercase.
True,
)
+ def test_pyodbc_extra_connect_azure(self):
+ # issue #5592
+ dialect = pyodbc.dialect()
+ u = url.make_url(
+ "mssql+pyodbc://@server_name/db_name?"
+ "driver=ODBC+Driver+17+for+SQL+Server;"
+ "authentication=ActiveDirectoryIntegrated"
+ )
+ connection = dialect.create_connect_args(u)
+ eq_(connection[1], {})
+ eq_(
+ connection[0][0]
+ in (
+ "DRIVER={ODBC Driver 17 for SQL Server};"
+ "Server=server_name;Database=db_name;"
+ "Authentication=ActiveDirectoryIntegrated",
+ ),
+ True,
+ )
+
def test_pyodbc_odbc_connect(self):
dialect = pyodbc.dialect()
u = url.make_url(