Connecting to SQL-Server

Tim Golden tim.golden at viacom-outdoor.co.uk
Fri Oct 8 04:47:48 EDT 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):

http://www.able-consulting.com/ADO_Conn.htm

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:

<code>
import odbc

dsn = [
  "Driver={SQL Server}", 
  "Server=VODEV1", 
  "Database=EVOTEST",
  "UID=evoreader",
  "Pwd=***"
]

db = odbc.odbc (";".join (dsn))
</code>

or, for trusted connections:

<code>
import odbc

trusted_dsn = [
  "Driver={SQL Server}", 
  "Server=VODEV1", 
  "Database=EVOTEST", 
  "Trusted_Connection=yes"
]

db = odbc.odbc (";".join (trusted_dsn))
</code>

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.

TJG



More information about the Python-list mailing list