[DB-SIG] Simple? ODBC connection issue
Dennis Benzinger
Dennis.Benzinger at gmx.net
Fri Oct 17 17:25:31 CEST 2008
Hi!
Am 17.10.2008 02:55, Peter Machell schrieb:
> I'm using pyodbc to connect to several databases.
>
> On one of them, the database password needs to be a variable.
>
> If I hard code the password, the connection works fine:
>
> cnxn = pyodbc.connect("DSN=test;UID=test;PWD=test")
>
> However substituting a variable fails:
>
> passwd='test'
> connectstring='pyodbc.connect("DSN=test;UID=test;PWD='+passwd+'")'
> cnxn = connectstring
> [...]
You have to many quotes in your code. Your second line creates a string
but does not call the connect function.
You can either use
passwd='test'
connectstring='DSN=test;UID=test;PWD='+passwd
cnxn = pyodbc.connect(connectstring)
if you need the connectstring variable. Or simply
passwd='test'
cnxn=pyodbc.connect("DSN=test;UID=test;PWD="+passwd)
HTH,
Dennis Benzinger
More information about the DB-SIG
mailing list