我正在尝试使用Microsoft的ODBC驱动程序17通过ODBC连接到SQL Server 2008 R2数据库。odbc.ini
文件包含:
[ODBC Data Sources]
MyDB=ODBC Driver 17 for SQL Server
[MyDB]
Description=MyDB test database
Driver=ODBC Driver 17 for SQL Server
Server=***.***.***.***
Port=1433
Database=DbName
UID=********
PWD=********
Encrypt = no
TrustServerCertificate = no
Security = TLSv1
数据库参数已验证且正确。odbcinst.ini
文件包含:
[Default]
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.2.1
[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.2.so.1.1
UsageCount=1
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.2.1
UsageCount=1
用于连接的代码如下(python):
import pyodbc
def connect():
connStr = 'DSN=MyDB;'
print(f'Connection: {connStr}')
cnxn = pyodbc.connect(connStr)
cur1 = cnxn.execute('SELECT top 2 * from MASTER')
res1 = cur1.fetchall()
print(res1)
if __name__ == "__main__":
connect()
结果是:
Connection: DSN=MyDB
[ODBC][2133819][1678232108.869580][__handles.c][460]
Exit:[SQL_SUCCESS]
Environment = 0x557e51cc9e80
[ODBC][2133819][1678232108.869650][SQLSetEnvAttr.c][189]
Entry:
Environment = 0x557e51cc9e80
Attribute = SQL_ATTR_ODBC_VERSION
Value = 0x3
StrLen = 4
[ODBC][2133819][1678232108.869720][SQLSetEnvAttr.c][381]
Exit:[SQL_SUCCESS]
[ODBC][2133819][1678232108.869746][SQLAllocHandle.c][377]
Entry:
Handle Type = 2
Input Handle = 0x557e51cc9e80
UNICODE Using encoding ASCII 'UTF-8' and UNICODE 'UCS-2LE'
[ODBC][2133819][1678232108.869836][SQLAllocHandle.c][513]
Exit:[SQL_SUCCESS]
Output Handle = 0x557e51ce8a80
[ODBC][2133819][1678232108.870183][SQLDriverConnectW.c][290]
Entry:
Connection = 0x557e51ce8a80
Window Hdl = (nil)
Str In = [DSN=MyDB][length = 8 (SQL_NTS)]
Str Out = (nil)
Str Out Max = 0
Str Out Ptr = (nil)
Completion = 0
[ODBC][2133819][1678232108.879971][__handles.c][460]
Exit:[SQL_SUCCESS]
Environment = 0x557e51d30ce0
[ODBC][2133819][1678232108.880053][SQLGetEnvAttr.c][157]
Entry:
Environment = 0x557e51d30ce0
Attribute = 65002
Value = 0x7fffaef27420
Buffer Len = 128
StrLen = 0x7fffaef273bc
[ODBC][2133819][1678232108.880185][SQLGetEnvAttr.c][273]
Exit:[SQL_SUCCESS]
[ODBC][2133819][1678232108.880229][SQLFreeHandle.c][220]
Entry:
Handle Type = 1
Input Handle = 0x557e51d30ce0
[ODBC][2133819][1678232108.880360][SQLDriverConnectW.c][699]
Exit:[SQL_ERROR]
[ODBC][2133819][1678232108.880402][SQLDriverConnect.c][748]
Entry:
Connection = 0x557e51ce8a80
Window Hdl = (nil)
Str In = [DSN=MyDB][length = 8 (SQL_NTS)]
Str Out = 0x7fffaef2b190
Str Out Max = 2048
Str Out Ptr = (nil)
Completion = 0
DIAG [08001] [Microsoft][ODBC Driver 17 for SQL Server]SSL Provider: [error:0A0C0103:SSL routines::internal error]
DIAG [08001] [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection
[ODBC][2133819][1678232108.884482][SQLDriverConnect.c][1637]
Exit:[SQL_ERROR]
[ODBC][2133819][1678232108.884519][SQLGetDiagRecW.c][535]
Entry:
Connection = 0x557e51ce8a80
Rec Number = 1
SQLState = 0x7fffaef2c994
Native = 0x7fffaef2c96c
Message Text = 0x557e51d98250
Buffer Length = 1023
Text Len Ptr = 0x7fffaef2c96a
[ODBC][2133819][1678232108.884612][SQLGetDiagRecW.c][596]
Exit:[SQL_SUCCESS]
SQLState = [08001]
Native = 0x7fffaef2c96c -> -1 (32 bits)
Message Text = [[Microsoft][ODBC Driver 17 for SQL Server]SSL Provider: [error:0A0C0103:SSL routines::internal error]]
[ODBC][2133819][1678232108.884703][SQLFreeHandle.c][290]
Entry:
Handle Type = 2
Input Handle = 0x557e51ce8a80
[ODBC][2133819][1678232108.884753][SQLFreeHandle.c][339]
Exit:[SQL_SUCCESS]
Traceback (most recent call last):
File "/home/data2.py", line 13, in <module>
connect()
File "/home/data2.py", line 7, in connect
cnxn = pyodbc.connect(connStr)
pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]SSL Provider: [error:0A0C0103:SSL routines::internal error] (-1) (SQLDriverConnect)')
有谁能告诉我哪里做错了吗?
谢谢
1条答案
按热度按时间mtb9vblg1#
在此特定情况下,通过在/etc/ssl/openssl.cnf文件底部添加以下内容修复了该问题: