Error when selecting data from table with JSON datatype
维护者通常 2 天内回复
@gargsaumya 已经在做这个了。
开始于 2025年9月26日。
评估
这个 Issue 还没有评估数据。
描述
Describe the bug
When calling cursor.execute to select a json column from a table you receive a runtime error RuntimeError: [Microsoft][ODBC Driver 18 for SQL Server]The connection is no longer usable because the server response for a previously executed statement was incorrectly formatted.
If you are seeing an exception, include the full exceptions details (message and stack trace).
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[13], [line 1](vscode-notebook-cell:?execution_count=13&line=1)
----> [1](vscode-notebook-cell:?execution_count=13&line=1) with connect(getenv("SQL_CONNECTION_STRING")) as conn: # type: ignore
2 with conn.cursor() as cursor:
3 cursor.execute("select * from SalesLT.CustomerJson")
File c:\python\notebook\.venv\Lib\site-packages\mssql_python\connection.py:1028, in Connection.__exit__(self, *args)
1021 """
1022 Exit the context manager.
1023
1024 Closes the connection when exiting the context, ensuring proper resource cleanup.
1025 This follows the modern standard used by most database libraries.
1026 """
1027 if not self._closed:
-> [1028](file:///C:/python/notebook/.venv/Lib/site-packages/mssql_python/connection.py:1028) self.close()
File c:\python\notebook\.venv\Lib\site-packages\mssql_python\connection.py:971, in Connection.close(self)
966 if not self.autocommit:
967 # If autocommit is disabled, rollback any uncommitted changes
968 # This is important to ensure no partial transactions remain
969 # For autocommit True, this is not necessary as each statement is committed immediately
970 log('info', "Rolling back uncommitted changes before closing connection.")
--> [971](file:///C:/python/notebook/.venv/Lib/site-packages/mssql_python/connection.py:971) self._conn.rollback()
972 # TODO: Check potential race conditions in case of multithreaded scenarios
973 # Close the connection
974 self._conn.close()
RuntimeError: [Microsoft][ODBC Driver 18 for SQL Server]The connection is no longer usable because the server response for a previously executed statement was incorrectly formatted.
To reproduce
Include a complete code listing (or project/solution) that we can run to reproduce the issue.
Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.
Run the following tsql in a database with the AdventureWorksLT sample data loaded.
select *
from (SELECT *
FROM [SalesLT].[Customer]
for json AUTO) dt
create table SalesLT.CustomerJson
(
CustomerID int primary key,
CustomerJson JSON
)
insert into SalesLT.CustomerJson (CustomerID, CustomerJson)
select 1, (SELECT *
FROM [SalesLT].[Customer]
for json AUTO)
with connect(getenv("SQL_CONNECTION_STRING")) as conn: # type: ignore
with conn.cursor() as cursor:
cursor.execute("select * from SalesLT.CustomerJson")
if cursor:
row = cursor.fetchone()
if row:
print(row.CustomerJson)
Expected behavior
A string is returned that is in JSON or convertible to JSON.
Further technical details
Python version: 3.12
SQL Server version: SQL database in Fabric
Operating system: uv
Additional context
Can share uv folder directly since it includes connection strings.
- 主要语言
- 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 于 15 天前认领。 未关闭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 于 42 天前认领,目前没有进行中的 PR。 未关闭announcement
microsoft/mssql-python#748 · 已指派 1 人 ·
维护者通常 2 天内回复
-
Connection pool can briefly exceed max_size when pooling is disabled under load可能已有人在做 @bewithgaurav 于 24 天前认领。 未关闭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
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
jbacalso24/mimry#291 ·
维护者通常 1 天内回复
-
good first issue
难度 2/5 1 小时以内 新手友好度 82/100
eli-alvarado/us-watchlist-alerts#14 ·
维护者通常 1 天内回复
-
from-review-extraction python severity:nit
难度 2/5 1-3 小时 新手友好度 80/100
LearningCircuit/local-deep-research#7462 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
cathrynlavery/diagram-design#441 ·
维护者通常 2 天内回复
-
[Cleanup] Include the public header in work_split.cpp可能已有人在做 @blozano-tt 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
tenstorrent/tt-metal#60850 ·
维护者通常 1 天内回复