Microsoft - SQL Server

Driver

Probably best to go for http://code.google.com/p/pyodbc/. I am using this driver because it is recommended by SQLAlchemy and used in the Django SQL Server driver.

Install

Note: To install in a virtual environment, see Issues, virtualenv below…

Usage

Parameters

first_name = '%%%s%%' % first_name
last_name = '%%%s%%' % last_name
sql = '''
    SELECT TOP 10 * FROM crm_user WITH(NOLOCK)
        WHERE first_name LIKE ? AND last_name LIKE ?
'''
data = db.fetchall(sql, (first_name, last_name,))

Note: This example also shows how to escape the % character. The standard parameter placeholder is the ? character.

Issues

virtualenv

I had lots of problems installing into a virtual environment. I couldn’t use easy_install or pip because I needed Microsoft Visual Studio 2003. The Windows installer will only install into the default environment.

In the end, the solution I found was to install pyodbc into my default environment, then create the virtual environment without the --no-site-packages option.