Get Python 2.7 Work with AWS and MSSQL 2008 R2

Tested on MSSQL 2008 R2 Express/Standard and Windows Server 2008 R2 Datacenter.

Works with Python 2.7 (x86) and PyScripter 2.5 (x86).

Get Python Run with AWS

Install 7zip

Download here.

Install Python 2.7 (x86)

Download here.

Optional: Install PyScripter 2.5 (x86)

Download here.

Install Boto Library

Boto is a Python interface to Amazon Web Services.

Download here. Extract using 7zip, then open command line, cd to extracted folder and type:

> install


Get Python Run with MSSQL 2008 R2

Need to do all the steps above plus those listed below.

Install PyMSSql

Download here (pymssql-1.0.3.win32-py2.7.‌exe).

The 2.X version of pymssql is also available (pymssql‑2.1.0.win32‑py2.7.exe). Use this one if you need a unicode friendly database interface.

Install Missing msvcr71.dll

Download here or here.

Copy file to C:\Windows\System32, or C:\Windows\system if running a 64bit OS. Open Windows terminal and run:

> regsvr32 msvcr71.dll

Don’t worry in you get an error message, it will still work. Python can now import _mssql correctly.

Connection Examples

Using Windows Authentication (Trusted Connection)

import _mssql
conn = _mssql.connect(server='localhost\SQLEXPRESS',database='master',trusted=True)

This, however, only works with pymssql v1.0.3 for me. Version 2 of pymssql (pymssql‑2.1.0.win32‑py2.7.exe) gives the following error:

 __init__() got an unexpected keyword argument 'trusted'

Using SQL Server Authentication Mode

Make sure mixed authentication mode is enabled.

import _mssql
conn = _mssql.connect(server='localhost\SQLEXPRESS',database='master',username="sandy",password="passwd")

Version 2 of pymssql works this way for me (no SQL instance name provided):

import _mssql
conn = _mssql.connect(server='localhost',database='master',username="sandy",password="passwd")

If SQL instance name is provided, connection fails due to an unknown reason:

Connection to the database failed for an unknown reason.

Leave a Reply

Your email address will not be published. Required fields are marked *