SQL Server from Linux with Kerberos and Trusted_Connection=yes

1,534 views
Skip to first unread message

tod davis

unread,
Mar 15, 2016, 5:17:58 PM3/15/16
to pyodbc

Good afternoon all


Using pyodbc, is it possible to connect to SQL Server from Linux using Kerberos credentials ?


CentOS 6.7

Python 2.7 (anaconda) and Python 2.6.6

Kerberos / Active Directory Integration

SQL Server 2008 R2


 

I *can* connect and query with a SQL Server local account as shown in the pyodbc documentation but not with Kerberos credentials.

 

*odbc.ini

[dsn_name]

Driver      = ODBC Driver 11 for SQL Server

Description = server

Trace       = No

Server      =server.domain.org

 

*odbcinst.ini
Description=Microsoft ODBC Driver 11 for SQL Server

Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0

Threading=1

UsageCount=1

[ODBC]

Trace = Yes

TraceFile = /tmp/msodbctrace.log

 

*works

cnxn = pyodbc.connect('DSN=dsn_name;UID=user;PWD=pass')

 

*does not work

cnxn = pyodbc.connect('DSN=dsn_name;Trusted_Connection=yes')

 

 

Thanks for any help you can provide.

dumischbaenger

unread,
Apr 19, 2016, 7:19:17 AM4/19/16
to pyodbc


Am Dienstag, 15. März 2016 22:17:58 UTC+1 schrieb tod davis:

CentOS 6.7

Python 2.7 (anaconda) and Python 2.6.6

Kerberos / Active Directory Integration

SQL Server 2008 R2



CentOS7
Python 3.4
 

 

I *can* connect and query with a SQL Server local account as shown in the pyodbc documentation but not with Kerberos credentials.

 

*odbc.ini

[dsn_name]

Driver      = ODBC Driver 11 for SQL Server

Description = server

Trace       = No

Server      =server.domain.org


[MSSQLTest]
Driver = ODBC Driver 13 for SQL Server
Server = host.db.local\myInstanceName,51818
Database = myDbName
Trusted_Connection = yes

 

 

*odbcinst.ini
Description=Microsoft ODBC Driver 11 for SQL Server

Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2270.0

Threading=1

UsageCount=1

[ODBC]

Trace = Yes

TraceFile = /tmp/msodbctrace.log

 


[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/unixodbc/drivers/mssql/libmsodbcsql-13.0.so.0.0
Threading=1
UsageCount=1


 

*works

cnxn = pyodbc.connect('DSN=dsn_name;UID=user;PWD=pass')

 

*does not work

cnxn = pyodbc.connect('DSN=dsn_name;Trusted_Connection=yes')

 

 


First check with klist if you have a TGT from your ADC.

My output of klist is:

Ticket cache: FILE:/tmp/krb5cc_554
Default principal: myUse...@MYDOMAIN.LOCAL

Valid starting       Expires              Service principal
19.04.2016 10:30:13  19.04.2016 20:30:13  krbtgt/MYDOMAI...@MYDOMAIN.LOCAL
19.04.2016 10:30:14  19.04.2016 20:30:13  MSSQLSvc/myDbServer.mydomain.local:51...@MYDOMAIN.LOCAL

If this is not the case try to obtain a ticket with kinit and check /etc/krb5.conf.

If you have a ticket I would test if it is possible to connect with sqlcmd.

If this works give python a try.
 

Thanks for any help you can provide.


HTH.

Regards,
Bernhard

tod davis

unread,
Apr 19, 2016, 7:30:14 AM4/19/16
to pyodbc
Thanks Bernhard.  Will give this a try later this week and report back.

Thanks for responding.

Tod
Reply all
Reply to author
Forward
0 new messages