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 _______________________________________________ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig