bulkcopy PyCore login is closed by SQL Server 2019 while ODBC and Go clients succeed (1.14.0)
維護者通常 2 天內回覆
@bewithgaurav 已經在處理了。
開始於 2026年9月10日。
評估
這個 Issue 還沒有評估資料。
描述
Describe the bug
cursor.bulkcopy() fails while opening its separate native/PyCore connection, although the normal mssql_python.connect() connection succeeds with the same server, database, SQL login, encryption settings, and process.
The failure occurs before destination metadata is read or any rows are sent. It reproduces with both a base table and a view, and even with an empty iterator.
Exception message:
RuntimeError: Failed to connect to SQL Server: Protocol Error: Failed to receive token during login response parsing.
Relevant filtered native TDS trace:
ERROR mssql_tds::message::login: Failed to receive token during login response parsing. Error: ConnectionClosed("Connection closed by server while reading TDS packet header")
DEBUG mssql_tds::connection_provider::tds_connection_provider: Connection attempt failed: Protocol Error: Failed to receive token during login response parsing.
ERROR mssql_py_core::connection: Failed to connect to SQL Server: Protocol Error: Failed to receive token during login response parsing.
This resembles #600, but the trace is different from the DatabaseMirroringPartner UnimplementedFeature fixed by microsoft/mssql-rs#69. This server reports SERVERPROPERTY('IsHadrEnabled') = 0; sys.database_mirroring has no partner or mirroring state for either master or the target database.
To reproduce
The following is the complete minimal reproduction. It creates and cleans up a small table through the working ODBC connection. Substitute environment variables for a SQL Server 2019 instance and SQL-authenticated test account with DDL permissions.
import os
import mssql_python
def braced(value: str) -> str:
return "{" + value.replace("}", "}}") + "}"
server = os.environ["MSSQL_TEST_SERVER"]
database = os.environ["MSSQL_TEST_DATABASE"]
username = os.environ["MSSQL_TEST_USERNAME"]
password = os.environ["MSSQL_TEST_PASSWORD"]
connection_string = ";".join(
(
f"SERVER={braced(server)}",
f"DATABASE={braced(database)}",
f"UID={braced(username)}",
f"PWD={braced(password)}",
"Encrypt=yes",
"TrustServerCertificate=yes",
"",
)
)
connection = mssql_python.connect(connection_string, timeout=20)
cursor = connection.cursor()
try:
cursor.execute("SELECT @@VERSION, DB_NAME(), ORIGINAL_LOGIN()")
print(tuple(cursor.fetchone())) # succeeds
cursor.execute("DROP TABLE IF EXISTS dbo.mssql_python_bulkcopy_login_repro")
cursor.execute(
"CREATE TABLE dbo.mssql_python_bulkcopy_login_repro (id int NOT NULL)"
)
connection.commit()
# Fails while PyCore opens its separate connection. The same failure occurs
# with [(1,)] and with an existing view as destination.
print(
cursor.bulkcopy(
"dbo.mssql_python_bulkcopy_login_repro",
iter(()),
timeout=10,
)
)
finally:
cursor.execute("DROP TABLE IF EXISTS dbo.mssql_python_bulkcopy_login_repro")
connection.commit()
cursor.close()
connection.close()
Also reproduced with these variations:
SERVER=hostSERVER=host,1433SERVER=tcp:host,1433- connecting to the target database and using a two-part destination name
- connecting to
masterand using a fully qualified three-part destination name fire_triggers=Falseandfire_triggers=True- base table and view destinations
Independent controls using the same server and SQL account all succeed:
- normal
mssql_python.connect()plusSELECT - ODBC sqlcmd 18.6
- Go sqlcmd 1.10.0
- ODBC bcp 18.6 initialization against the same table and view (
0 rows copied, exit code 0)
All clients connect to the same explicit TCP port 1433 with encryption enabled and the development certificate trusted.
Expected behavior
cursor.bulkcopy() should establish its native connection and bulk copy the rows when the normal driver connection and other TDS/BCP clients can connect using the same endpoint and credentials.
If the server closes the login connection, the driver should ideally preserve enough diagnostic context to identify the rejected login feature or packet.
Further technical details
Python version: 3.12.11
mssql-python version: 1.14.0
Bundled mssql-python-odbc version: 18.6.2.1
SQL Server version: SQL Server 2019 Standard, 15.0.4430.1
Operating system: macOS 26.5.2, arm64
Additional context
- The target server is reachable and remains available throughout the tests.
- There is no separate Bulk Copy port; all successful and failing clients use TCP 1433.
Encrypt=yes;TrustServerCertificate=yesis explicitly present, so this does not appear to be the already-fixed connection-parameter forwarding problem from #501.- No credentials, hostnames, or packet contents are included in this report.
- 主要語言
- Python
- 星號
- 478
- 分支
- 62
- 平均合併
- 3 天 19 分鐘
- 30 天內合併 PR
- 28
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
microsoft/mssql-python 的其他 Issue
-
area: bulk-copy triage needed
難度 2/5 1-3 小時 新手友好度 70/100
microsoft/mssql-python#843 · 1 則留言 ·
維護者通常 2 天內回覆
-
triage needed
難度 4/5 3-5 天 新手友好度 35/100
microsoft/mssql-python#846 · 1 則留言 ·
維護者通常 2 天內回覆
-
macOS: encrypted connections fail after Homebrew moved the `openssl` alias to `openssl@4`可能已有人在做 @bewithgaurav 於 14 天前認領。 未關閉area: packaging-platform bug triage needed
難度 4/5 3-5 天 新手友好度 55/100
microsoft/mssql-python#826 · 2 則留言 · 已指派 1 人 ·
維護者通常 2 天內回覆
-
Announcement: mssql-python is coming to Django through mssql-django 2.0可能重新可做 @bewithgaurav 於 41 天前認領,目前沒有進行中的 PR。 未關閉announcement
microsoft/mssql-python#748 · 已指派 1 人 ·
維護者通常 2 天內回覆
-
Connection pool can briefly exceed max_size when pooling is disabled under load可能已有人在做 @bewithgaurav 於 23 天前認領。 未關閉area: connectivity-auth bug triage done under development
難度 4/5 3-5 天 新手友好度 62/100
microsoft/mssql-python#746 · 1 則留言 · 已指派 1 人 ·
維護者通常 2 天內回覆
查看 microsoft/mssql-python 的全部 Issue
相似的 Issue
-
good first issue
難度 2/5 1-3 小時 新手友好度 85/100
btclib-org/btclib-node#1955 ·
維護者通常 1 天內回覆
-
documentation v0.9.2
難度 2/5 半天 新手友好度 72/100
khuisman/mcp-gee-sweet#1033 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
ossf/cve-bin-tool#5966 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 2 天內回覆
-
write_iceberg ignores the table's write.parquet.compression-codec property可能已有人在做 @YuangGao 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
Eventual-Inc/Daft#7606 ·
維護者通常 1 天內回覆