Skip to content Skip to sidebar Skip to footer

Mixing Strings And Input Variable In Sql Connection String Using Pyodbc Library - Python

I've had a look around SO and couldn't find this particular issue. So I have an ext config.txt file which is used to obtain values which are stored in variables in the python progr

Solution 1:

So I managed to find the fix and looks like it was an error with the parsed string:

incorrect:

odbc.connect('\''DRIVER='+ str(driver) +  ' SERVER=' + str(server) + ' DATABASE=' + str(database)  +  ' Trusted_Connection='+ str(trusted)+'\'')

correct:

odbc.connect('DRIVER='+driver+';SERVER='+server+';DATABASE='+database+';Trusted_Connection='+trusted) 

Post a Comment for "Mixing Strings And Input Variable In Sql Connection String Using Pyodbc Library - Python"