Get Python 2.7 to 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 from http://www.7-zip.org/download.html.

Install Python 2.7 (x86)

Download from http://www.python.org/downloads/.

Optional: Install PyScripter 2.5 (x86)

Download from http://sourceforge.net/projects/pyscripter/.

Install Boto Library

Boto is a Python interface to Amazon Web Services.

Download from http://github.com/boto/boto/. Change to extracted folder and type:

> setup.py install

All done here.

Get Python to Run with MSSQL 2008 R2

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

Install PyMSSql

Download from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pymssql.

A 2.x version of pymssql should also available. Use this one if you need a unicode friendly database interface.

Install Missing msvcr71.dll

Download from http://www.dll-files.com/dllindex/dll-files.shtml?msvcr71 or http://cloud.addictivetips.com/wp-content/uploads/2010/12/Msvcp71.dll-And-Msvcr71.dll-files.zip.

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 *