0

I am trying to access a SQL Server in two ways.

Method 1:

Using pyodbc after installing ODBC Driver in my local machine:

import pyodbc


conn = pyodbc.connect(driver='{ODBC Driver 18 for SQL Server}',
                      server=my_server,
                      database=my_database,
                      Trusted_Connection='yes',
                      uid=my_uid,
                      pwd=my_pwd,
                      domain=my_domain
                      )

Method 2:

Using jaydebeapi with JDBC mssql-jdbc-7.2.2.jre11.jar file

import jaydebeapi


conn = jaydebeapi.connect("com.microsoft.sqlserver.jdbc.SQLServerDriver",
                          f"""jdbc:sqlserver://my_server:1433;
                          databaseName=my_database""",
                          [my_uid, my_pwd],
                          "jars/mssql-jdbc-7.2.2.jre11.jar")

In method 1, I can download data fine. However, in method 2, I receive this error

com.microsoft.sqlserver.jdbc.SQLServerException: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'my_uid'. ClientConnectionId:cc46fb71-72a8-4fed-ad85-d00cc2f01680

I am running both methods above from a MacBook (if that matters at all).

What causes the failed login for method 2? I obviously have access to the database since it works for method 1.

Tristan Tran
  • 1,351
  • 1
  • 10
  • 36
  • Refer the below: https://stackoverflow.com/questions/17372606/sqlserver-login-failed-for-user – Mouli Sanketh Maturi Oct 10 '22 at 06:32
  • The JDBC connection is trying to use SQL Login authentication. The ODBC connection is doing something different. Is your Macbook joined to an Active Directory/Kerberos authentication domain? – AlwaysLearning Oct 10 '22 at 07:10
  • @AlwaysLearning Yes, in both cases, the login credential is my Active Directory login as well. – Tristan Tran Oct 10 '22 at 07:49
  • SQL Login authentication != Active Directory authentication. Since you're using such an old JDBC driver you'll need to ensure that `sqljdbc_auth.dll` is in your `java.library.path` and that `;integratedSecurity=true` is in your connection string properties. – AlwaysLearning Oct 10 '22 at 09:11

0 Answers0