4
votes

I am trying to connect to my database on MS SQL Server 2016 using pyodbc via the below python script from my laptop (on Windows 10) and planning to have the code deployed in a Linux RHEL 6.4 server.

conn=pyodbc.connect('Driver={SQL Server};'
                'Server=DB_Instance;'
                'Database=DB_Name;'
                'UID=user_name;'
                'PWD=password;'
                'Trusted_Connection=no;');

At my laptop, SQL Server (version: 10.00.17763.01) and SQL Server Native Client 11.0 (version: 2011.110.7493.04) are already available.

While executing the python script from my laptop, I am getting the below error message.

pyodbc.operationalError: ('08001', '[08001] [Microsoft] [ODBC SQL Server Driver][DBNETLIB]SSL Security error (18) (SQLDriverConnect); [08001] [Microsoft] [ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (SECDoClientHandshake()). (772)')

As per the organization standard, TLS 1.0 is disabled on the windows server where the SQL Server is installed in the network. Since I am accessing the database via python script, we cannot temporarily enable TLS 1.0. I am looking for a direction. Any help is greatly appreciated!!

1
Can you try using ODBC Driver 17 for SQL Server and see if that works for you?Gord Thompson
Thank you Gord. This fixed my issues in my laptop on Windows 10. Will see how this can be done in Linux server and keep it posted. Appreciate your help!Guna
I was facing different set of errors. While adding the port number in addition to the server name, the problem got resolved. The ODBC Driver name also needs to be updated. conn=pyodbc.connect('Driver={ODBC Driver 17 for SQL Server};' 'Server=DB_Instance,port;' 'Database=DB_Name;' 'UID=user_name;' 'PWD=password;' 'Trusted_Connection=no;');Guna

1 Answers

3
votes

Gord Thompson pointed Guna in the right direction in the comments:

Can you try using ODBC Driver 17 for SQL Server and see if that works for you?

– Gord Thompson

Guna said that this worked:

I was facing different set of errors. While adding the port number in addition to the server name, the problem got resolved. The ODBC Driver name also needs to be updated. conn=pyodbc.connect('Driver={ODBC Driver 17 for SQL Server};' 'Server=DB_Instance,port;' 'Database=DB_Name;' 'UID=user_name;' 'PWD=password;' 'Trusted_Connection=no;');

– Guna

Posting this as a community Wiki just so that any searchers can see quickly that it was answered.