|
Python Connector for SQL Server Connect to SQL Server from Python using SSL/TLS |
|
Transport Layer Security (TLS) is a security protocol for accessing remote machines over untrusted networks. A primary use case of TLS is encrypting the communication between web applications and servers. It runs on top of TCP/IP to secure client-server communications and allows a TLS-enabled client to authenticate itself to a TLS-enabled server and vice versa. TLS evolved from a previous encryption protocol called Secure Sockets Layer (SSL), and the terms TLS and SSL are sometimes used interchangeably.
During server authentication, the client application uses public-key cryptography (PKI) algorithms to verify the server's identity by checking that the server's certificate is issued by a trusted certificate authority (CA) and proves the ownership of the public key. Similarly, TLS client authentication allows the server to validate the client's identity. The client and server can also authenticate each other using self-signed certificates. However, you will only want to use a self-signed certificate for an internal network or a development server.
After establishing a TLS connection, the client and server can exchange symmetrically encrypted messages with a shared secret key. TLS is the recommended method for establishing a secure connection to SQL Server due to its more straightforward configuration and higher performance than SSH.
To establish a TLS connection to SQL Server, set the UseEncryptionforData parameter to True. For more information about securing TCP/IP connections with TLS, see the SQL Server documentation.
import devart.sqlserver
connect() module method and obtain a connection object.
my_connection = devart.sqlserver.connect(
Authentication="SQLServer",
Server="your_server",
Database="your_database",
UserId="your_username",
Password="your_password",
UseEncryptionforData="True"
)