Can Pymssql have a secure connection (SSL) to MS SQL Server?

不想你离开。 提交于 2019-12-02 03:25:34

问题


I'm making queries from a MS SQL server using Python code (Pymssql library) however I was wondering if there was any way to make the connection secure and encrypt the data being sent from the server to python?

Thanks


回答1:


pymssql certainly claims to be able to work with encrypted connections to the SQL Server (via OpenSSL). One reason why some might believe it to be impossible is that Windows releases of pymssql versions prior to 2.1.2 were shipped with pymssql statically linked to FreeTDS for unencrypted connections only.

Starting with version 2.1.2, the Windows release of pymssql is shipped dynamically linked to FreeTDS so it can support both unencrypted connections (via FreeTDS alone) or encrypted connections (via FreeTDS and OpenSSL). For details – and an important update re: versions 2.1.3 and later – see the related answer here.




回答2:


Yes, it can.

You need FreeTDS which supports SSL via OpenSSL. If you happened to use Linux (or Docker on Windows), it's quite easy to install standalone FreeTDS in Debian:

apt-get update
apt-get install freetds-bin freetds-dev
pip install pymssql

Don't use pymssql with bundled FreeTDS library, it does not support SSL apparently. The bundled library is used when you set env variable PYMSSQL_BUILD_WITH_BUNDLED_FREETDS=1 before installing pymssql.




回答3:


If you want to connect SQL server using secured connection using pymssql then you need to provide "secure" syntax in your host..

for e.g.

unsecured connection host : xxx.database.windows.net:1433 secured connection host : xxx.database.secure.windows.net:1443




回答4:


Unfortunately there's no way, but you could use pyodbc.



来源:https://stackoverflow.com/questions/28724427/can-pymssql-have-a-secure-connection-ssl-to-ms-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!