Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

bulkcopy PyCore login is closed by SQL Server 2019 while ODBC and Go clients succeed (1.14.0)

已关闭
#750 4 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 2 天内回复

@bewithgaurav 已经在做这个了。

开始于 2026年9月10日。

评估

这个 Issue 还没有评估数据。

描述

area: bulk-copy bug triage done
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=host
  • SERVER=host,1433
  • SERVER=tcp:host,1433
  • connecting to the target database and using a two-part destination name
  • connecting to master and using a fully qualified three-part destination name
  • fire_triggers=False and fire_triggers=True
  • base table and view destinations

Independent controls using the same server and SQL account all succeed:

  • normal mssql_python.connect() plus SELECT
  • 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=yes is 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

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/mssql-python 的其他 Issue

查看 microsoft/mssql-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。