Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions mssql/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def _build_connection_string(self, conn_params, driver):
user = conn_params.get('USER', None)
password = conn_params.get('PASSWORD', None)
port = conn_params.get('PORT', None)
trusted_connection = conn_params.get('Trusted_Connection', 'yes')
trusted_connection = conn_params.get('Trusted_Connection', None)

options = conn_params.get('OPTIONS', {})
dsn = options.get('dsn', None)
Expand Down Expand Up @@ -345,10 +345,18 @@ def _build_connection_string(self, conn_params, driver):
cstr_parts['PWD'] = password
elif 'TOKEN' not in conn_params:
if ms_drivers.match(driver) and 'Authentication=ActiveDirectoryMsi' not in options_extra_params:
cstr_parts['Trusted_Connection'] = trusted_connection
# Do not implicitly force Windows authentication.
# Only include Trusted_Connection when explicitly configured.
if trusted_connection is not None:
cstr_parts['Trusted_Connection'] = trusted_connection
else:
cstr_parts['Integrated Security'] = 'SSPI'

# Preserve legacy behavior for non-Microsoft drivers.
# For Microsoft drivers, avoid injecting an authentication mode
# unless explicitly requested through USER/PASSWORD, TOKEN,
# or Trusted_Connection.
if not ms_drivers.match(driver):
cstr_parts['Integrated Security'] = 'SSPI'

cstr_parts['DATABASE'] = database

if ms_drivers.match(driver) and os.name == 'nt':
Expand Down
Loading