mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.95k stars 563 forks source link

Add support for the SQL Server TDS 8.0 protocol #1131

Closed rgl closed 1 year ago

rgl commented 1 year ago

SQL Server 2022 is now using TDS 8.0 and TLS 1.3 and would be nice to have support for it. This new protocol version now directly works over TLS (strict connection encryption is enabled with encrypt=strict and requires ODBC Driver for SQL Server version 18.1.2.1 or higher).

PS this was probably done by https://github.com/mkleehammer/pyodbc/pull/1128 and will be available at the next pyodbc version?

keitherskine commented 1 year ago

It's important to understand that pyodbc does not know or care about TDS/TLS. TLS/TDS is a matter for your ODBC driver manager and the database driver. The protocol used is largely defined in the connection string provided to pyodbc in the connect() function. For the latest SQL Server ODBC drivers, this probably means adding the "Encrypt" attribute to the connection string, for example:

conn = pyodc.connect("DRIVER={ODBC Driver 18 for SQL Server};UID=user;PWD=password;Encrypt=Optional")

pyodbc passes the (verbatim) connection string to the driver manager for connecting to your database (pyodbc does not even attempt to parse the connection string), and that functionality is available in the current pyodbc release (4.0.35).

If you're still getting an error after adding the "Encrypt" keyword, please include the error message here, with other details about your scenario.

v-chojas commented 1 year ago

Keith is correct, this has nothing to do with pyODBC.

For TDS8 you just need to specify Encrypt=Strict in connection string (and connect to server that also has it enabled.)

rgl commented 1 year ago

Thank You!

I'm sorry, but for some odd reason, I thought the ODBC driver was somehow bundled/installed with this wheel/package. After installing the driver in the machine, it now works as expected.