I have an issue trying to call my uid and password through pyodbc.connect
Here is my odbc.ini:
[my_dsn]
Driver= SQL Server
Server=my_server
User=uid_reader
Password=password_reader
MultiSubnetFailover=Yes
Database=master
When I hard code, it works perfectly and I can connect
test_uid = 'uid_reader'
test_password = 'password_reader'
conn = pyodbc.connect(r'DSN=my_dsn;UID={a};PWD={b}'.format(a=test_uid,b=test_password))
When I call my dsn variables from my odbc.ini, it doesn't work
conn = pyodbc.connect(r'DSN=my_dsn;UID=User;PWD=Password')
Error: ('28000', "[28000] [unixODBC][Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'User'. (18456) (SQLDriverConnect)")
I would like to hide the password in my odbc.ini so it doesn't appear when I call pyodbc.connect
User
is being used as the value for UID. What happens if you do not specify the user and password in the connect string? – mhawkeconn = pyodbc.connect(r'DSN=my_dsn;UID=User;PWD=Password')
seems like it's supposed to use the literal string value ofmy_dsn
,User
andPassword
. My understanding is you should be doing string formatting like you did in your hardcode version, but instead of pointing to the variable, point it to the loaded config. – r.ook