我使用的是 Python 3.6.12,但无法与我的 SQL Server 数据库建立成功连接。如果有人能给我指点如何解决这个问题,我将不胜感激。
这是我的代码:
import pyodbc
import sqlalchemy
from sqlalchemy import create_engine
engine = create_engine('mssql+pyodbc:<INSERTDBINSTANCEANDDBNAME>?driver=SQL Server Native Client 11.0')
conn = engine.connect()
print(engine.table_names())
conn.close()
这将返回以下错误:
OperationalError: (pyodbc.OperationalError) ('08001', '[08001] [Microsoft][SQL Server Native Client 11.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. (-1) (SQLDriverConnect); [08001] [Microsoft][SQL Server Native Client 11.0]Login timeout expired (0); [08001] [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (-1)')
(Background on this error at: http://sqlalche.me/e/13/e3q8)
经过初步研究,团队可以看到,如果在 SQL Server 端禁用 TLS 1.2 安全设置,则连接成功。出于安全原因,这显然不是一个选项,我被建议升级 Python 环境 - 但是我已经3.6.12
知道为什么它不能处理 TLS 1.2 连接?