[DB-SIG] Simple? ODBC connection issue

Art Protin aprotin at research.att.com
Fri Oct 17 16:29:49 CEST 2008


Dear folks,
    I read the code and think I see the problem.

    Chris Clark wrote:

> On 10/16/2008 5:55 PM, Peter Machell wrote:
>
>> ...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
>> ...
>
I would expect that if one were to follow this code with
print cnxn
one would get the string 'pyodbc.connect("DSN=test;UID=test;PWD=test")'
and not some reference to a connection object.

To do what he seemed to have been trying would take:

passwd='test'
connectstring='DSN=test;UID=test;PWD=' + passwd
cnxn = pyodbc.connect(connectstring)

But I agreee that Vernon Cole's code is better.
Or how about

cnxn = pyodbc.connect('DSN=test;UID=test;PWD=' + passwd)
or
cnxn = pyodbc.connect('DSN=test;UID=test;PWD=%s' % passwd)

>
>
> Try printing the string to screen first :-)
>
> You have single quotes embedded in the variables based so the variable 
> is never in place.

I think this analysis by Chris Clark is not correct.

> Use % markers instead and make your life easier :-)
>
>
>
> _______________________________________________
> DB-SIG maillist  -  DB-SIG at python.org
> http://mail.python.org/mailman/listinfo/db-sig

    Thank you all,
    Art Protin




More information about the DB-SIG mailing list