Connecting to SQL-Server

Tim Golden tim.golden at
Fri Oct 8 10:47:48 CEST 2004

[Greg Lindstrom]
> I'm running Python 2.3 on a Windows XP box and am trying to get connected to
> an MS SQL-Server.  I have found (seemingly) conflicting methods to connect
> using the odbc module in the win32-all extensions.  I have seen both of the
> following:
> db = odbc.odbc('DSN/UID/PASSWORD)
> and
> db=odbc.odbc('DSN=dsn;UID=uid;PWD=password)

[... snip description of problem solved by other people ...]

I know I'm coming late to this particular party now that 
others have solved the particular problem. But I wanted to
offer a couple of things. One is this page (just in case you
hadn't come across it):

I come back here every time I have a problem with an
ODBC connection string.

On the back of that, I almost always use a DSN-less
connection something like this:

import odbc

dsn = [
  "Driver={SQL Server}", 

db = odbc.odbc (";".join (dsn))

or, for trusted connections:

import odbc

trusted_dsn = [
  "Driver={SQL Server}", 

db = odbc.odbc (";".join (trusted_dsn))

Obviously the server / database etc. can be variables
pulled from a configuration file etc. This way, I
don't have to set up a system/user-dsn on each computer
I run on.


More information about the Python-list mailing list