I have searched the web all day tried many solutions but none works. I can manually connect to this server but not with Python I get this error:
pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect); [08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (5); [08001] [Microsoft][ODBC SQL Server Driver]Invalid connection string attribute (0)')
I have tried the following:
A)
cnx = pyodbc.connect(Driver='{SQL Server}', SERVER=self.DBserver, DATABASE=xyz, username=self.DBusername, password=self.DBpassword, PORT = 1433)
B)
cnx = pyodbc.connect('''Driver={SQL Server}; SERVER=tcp:<self.DBserver>; PORT=self.DBPort; DATABASE=xyz; UID=self.DBusername; PWD=self.DBpassword''')
C)
cnx = = pyodbc.connect(Driver='{SQL Server}', SERVER=self.DBserver, DATABASE=xyz, UID=self.DBusername, PWD=self.DBpassword)
self.DBusername
not the value of that property. However, your second example does use the correct attribute namesUID=
andPWD=
. Also, Microsoft's ODBC drivers do not usePORT=
, but you've shown the port as 1433 so it presumably doesn't matter because that's the default. Try your second approach using anf'''string'''
and see if that helps. – Gord Thompsonself
variables do not propagate. – Parfait