0

related to this question Error 28000: Login failed for user DOMAIN\\user with pyodbc

I was able to solve the login failed error listed there but after adding the Trusted_Connection parameter, I am getting the below error. any idea how to solve this? I followed the instructions on microsoft's documentation here https://learn.microsoft.com/en-us/sql/connect/python/pyodbc/python-sql-driver-pyodbc?view=sql-server-2017

cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password+';Trusted_Connection='+tc)


pyodbc.Error: ('HY000', "[HY000] [Microsoft][ODBC Driver 17 for 
SQL Server]SSPI Provider: Server (MSSQLSvc/<server>:<port>@<domain>) 
unknown while looking up 'MSSQLSvc/<server>:<port>@<domain>’ 
(cached result, timeout in 1073 sec) (851968) (SQLDriverConnect)")
greenteam
  • 305
  • 5
  • 16
  • Are you trying to connect from a Windows machine or a non-Windows machine? – Gord Thompson Feb 19 '19 at 23:13
  • @GordThompson From a Mac running High Sierra. I'm able to connect to the same database from DBVisualizer for what its worth – greenteam Feb 19 '19 at 23:14
  • 1
    Is `Trusted_Connection=no` ? Does your `SERVER=` value contain anything other than the server IP address or DNS name (no instance name or port value)? – Gord Thompson Feb 19 '19 at 23:42
  • FWIW, [this page](http://confluence.dbvis.com/display/UG100/Using+SQL+Server+Single-Sign-On+or+Windows+Authentication) says that the jTDS JDBC driver is bundled with DbVisualizer, so that might explain why you can connect with DbVisualizer (JDBC + jTDS) but not with pyodbc (ODBC + ODBC Driver 17 for SQL Server). – Gord Thompson Feb 20 '19 at 00:23
  • @GordThompson there's a port but I tried adding that already too. Trusted_Connection is set to yes. And yeah, I'm not sure how to use jTDS JDBC driver with pyodbc. I tried pointing the driver variable to the same path where the jTDC jar is as well with no luck – greenteam Feb 20 '19 at 00:45
  • pyodbc works with ODBC drivers, not JDBC drivers, so you can't use jTDS with pyodbc. For `Trusted_Connection=yes` Microsoft's ODBC drivers for SQL Server on Mac/Linux require that you use Kerberos for authentication. If your SQL Server requires Windows authentication (as opposed to SQL Server authentication) and you don't have Kerberos available then you might have better luck using either pyodbc with FreeTDS ODBC, or JayDeBeApi with jTDS as described [here](https://stackoverflow.com/a/25614063/2144390), substituting the jTDS dependencies for UCanAccess dependencies, of course. – Gord Thompson Feb 20 '19 at 00:58

0 Answers0