1

I am using adodbapi library for database connection to SQL Server.

My below connection string works perfect with SQL Server authentication-

config = configparser.ConfigParser()
config.read("C:/configsql.ini")
_SERVER_NAME = config['SQL']['SERVER_NAME']
_DATABASE = config['SQL']['DATABASE']
_USERNAME = config['SQL']['USERNAME']
_PASSWORD = config['SQL']['PASSWORD']
conn = adodbapi.connect("PROVIDER=MSOLEDBSQL;Data Source={0};Database={1};UID={2};PWD={3};".format(_SERVER_NAME,_DATABASE,_USERNAME,_PASSWORD))
return conn

When I try to perform connection using windows authentication it does not works.

I modified connection string as below:

conn = adodbapi.connect("PROVIDER=MSOLEDBSQL;Data Source={0};Database={1};Integrated Security=SSPI;Persist Security Info=False".format(_SERVER_NAME,_DATABASE))

and I'm getting this exception:

Traceback (most recent call last):
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\adodbapi\adodbapi.py", line 113, in connect

co.connect(kwargs)

File "C:\Program Files (x86)\Python 3.5\lib\site-packages\adodbapi\adodbapi.py", line 275, in connect

self.connector.Open() # Open the ADO connection

File "", line 3, in Open
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\win32com\client\dynamic.py", line 287, in ApplyTypes

result = self.oleobj.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)

pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Driver for SQL Server', 'Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication.', None, 0, -2147467259), None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "Workflow.py", line 47, in sql_connection

conn = adodbapi.connect("PROVIDER=MSOLEDBSQL;Data Source={0};Database={1};Integrated Security=SSPI;Persist Security Info=False".format(_SERVER_NAME,_DATABASE))

File "C:\Program Files (x86)\Python 3.5\lib\site-packages\adodbapi\adodbapi.py", line 117, in connect

raise api.OperationalError(e, message)

adodbapi.apibase.OperationalError: (com_error(-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Driver for SQL Server', 'Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication.', None, 0, -2147467259), None), 'Error opening connection to "PROVIDER=MSOLEDBSQL;Data Source=TESTSERVER;Database=TEST;Integrated Security=SSPI;Persist Security Info=False"')

Please can anyone let me know how to make connection with SQL Server using Windows authentication?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2961127
  • 963
  • 2
  • 17
  • 29

0 Answers0