Question

For testing purposes, I am attempting to setup a SQL Server database on my local machine and connect to it using adodbapi in Python. I used SQL Server Management Studio 2008 r2 to create a database and table. I enabled the SQL Server Browser service, but I am still unable to connect using adodbapi. Using this connections string:

adodbapi.connect(r'Provider=SQLOLEDB;Data Source=COMPUTERNAME.\SQLEXPRESS;Initial Catalog=Test;User ID=userName; Password=password;')

I get the following error:

Traceback (most recent call last): File "", line 1, in File "C:\Python26\ArcGIS10.0\lib\site-packages\adodbapi\adodbapi.py", line 307, in connect raise OperationalError(e, "Error opening connection: " + connection_string) OperationalError: (com_error(-2147352567, 'Exception occurred.', (0, u'Microsoft OLE DB Provider for SQL Server', u'[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.', None, 0, -2147467259), None), 'Error opening connection: Provider=SQLOLEDB;Data Source=COMPUTERNAME.\SQLEXPRESS;Initial Catalog=Test;User ID=userName; Password=password;')

Any insight into what I'm missing?

Was it helpful?

Solution

I did a little more digging around and I ended up haphazardly stumbling on the answer. I was missing "Integrated Security=SSPI" in my connection string and it turns out I didn't need the dot before "\SQLEXPRESS" in my data source. Here's the connection string that worked for me:

adodbapi.connect(r'Provider=SQLOLEDB;Data Source=COMPUTERNAME\SQLEXPRESS;Initial Catalog=Test;User ID=COMPUTERNAME\USERNAME; Password=PASSWORD;Integrated Security=SSPI')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top