-
Notifications
You must be signed in to change notification settings - Fork 33
Description
Describe the bug
While trying to connect using ActiveDirectoryPassword authentication, I get the following error:
Login failed for user ''
It seems to ignore the UID parameter in the connection string.
If I remove the "Authentication=ActiveDirectoryPassword;", I'm able to see the UID populated correctly.
Exception message:
RuntimeError: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Login failed for user ''.
Stack trace:
File "/data-00/xxx/xxx/venv/lib64/python3.12/site-packages/mssql_python/db_connection.py", line 36, in connect
conn = Connection(connection_str, autocommit=autocommit, attrs_before=attrs_before, timeout=timeout, **kwargs)
File "/data-00/xxx/xxx/venv/lib64/python3.12/site-packages/mssql_python/connection.py", line 203, in __init__
self._conn = ddbc_bindings.Connection(self.connection_str, self._pooling, self._attrs_before)
To reproduce
def get_connection(srv, db, uid, pwd):
conn_str = f"""
Server={srv};
Database={db};
Authentication=ActiveDirectoryPassword;
UID={uid}@your.domain.com;
PWD={pwd};
Encrypt=Yes;
TrustServerCertificate=Yes;
"""
try:
conn = mssql_python.connect(conn_str)
return conn
except Exception as e:
raise e
if __name__ == "__main__":
conn = get_connection("<server>","testdb","user","password")Further technical details
Python version: 3.12.11 (venv used)
SQL Server version: SQL Server 16.0.4210.1
Operating system: Red Hat Enterprise Linux 8.10
ODBC Driver:
odbcinst -q -d
[ODBC Driver 18 for SQL Server]
Additional Context
Before switching to ODBC Driver 18, I previously had installed ODBC Driver 17, but the error persisted.
I tried without format strings "f" and also placing the connection string directly into a single line.
I don't know whether it's relevant or not, but the same connection string (without the authentication parameter) was working fine with pymssql.