Python – Connecting to MS-SQL from pyodbc using windows authentication

odbcpyodbcpythonsql serverwindows-authentication

I am trying to connect to MSSQL server using pyodbc. I can connect to the server and query it using the basic authentication mode as:

connection = pyodbc.connect("DRIVER={Easysoft ODBC-SQL Server};SERVER=192.168.2.119;DATABASE=dbame;UID=**;PWD=****")

Connection to MSSQL can also be done using Windows Authentication where it takes the parameters

DOMAIN
USERNAME
PASSWORD

I don't know how to use this sort of credential from pyodbc to connect to the MSSQL Server.

Furthermore, the ODBC driver I am using (Easysoft ODBC-SQL Server) needs licensing. Don't we get such drivers for free?

Best Answer

The Easysoft SQL Server driver parameters to use NTLM authentication are

Trusted_Domain=<domain name>
NTLMv2=Yes|No
Trusted_Connection=Yes|No

And UID, PWD as usual.

NTLM can also be triggered simply using a UID that looks like

DOMAIN\USER

If you want to use Kerberous, the following can be set

ServerSPN=SPN

Its all the the user guide for the driver

Related Topic