Archive for October, 2011

Accessing SQL Server from Python

It’s really not hard to access a SQL Server database from python, but you have to make sure everything is set up correctly.

First, make sure that the database server is set up for “Windows and SQL Server Authentication.” This can be set in the server security properties (in SQL Server Management Studio = SSMS, right click the server and go to Properties > Security). I spent quite a while pulling my hair out about failed logins, when this was the issue. After changing this setting, you’ll need to restart the server (using the Windows services administrative panel).

Then, within SSMS create a login, and a user for each database connected to that login, and make sure the user has been GRANTed access to the database (giving it the owner role is the easiest way to do that).

Now you should be able to login from python. Using adodbapi:

>>> adodbapi.connect(“Provider=SQLOLEDB; Data Source=.\SQLEXPRESS; Initial Catalog=database_name; User Id=user_id; Password=user_password”)



Leave a comment