Error when selecting data from table with JSON datatype
Mantenedores costumam responder em até 2 dias
@gargsaumya já está trabalhando nisso.
Desde 26/9/2025.
Avaliação
Esta issue ainda não foi avaliada.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 478
- Forks
- 62
- Merge médio
- 3d 19min
- PRs com merge (30d)
- 28
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de microsoft/mssql-python
-
area: bulk-copy triage needed
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
microsoft/mssql-python#843 · 1 comentário ·
Mantenedores costumam responder em até 2 dias
-
triage needed
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
microsoft/mssql-python#846 · 1 comentário ·
Mantenedores costumam responder em até 2 dias
-
macOS: encrypted connections fail after Homebrew moved the `openssl` alias to `openssl@4`Talvez já em andamento @bewithgaurav assumiu há 15 dias. Abertaarea: packaging-platform bug triage needed
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 55/100
microsoft/mssql-python#826 · 2 comentários · 1 responsável ·
Mantenedores costumam responder em até 2 dias
-
Announcement: mssql-python is coming to Django through mssql-django 2.0Talvez livre de novo @bewithgaurav assumiu há 42 dias e não há nenhum pull request aberto. Abertaannouncement
microsoft/mssql-python#748 · 1 responsável ·
Mantenedores costumam responder em até 2 dias
-
Connection pool can briefly exceed max_size when pooling is disabled under loadTalvez já em andamento @bewithgaurav assumiu há 24 dias. Abertaarea: connectivity-auth bug triage done under development
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 62/100
microsoft/mssql-python#746 · 1 comentário · 1 responsável ·
Mantenedores costumam responder em até 2 dias
Todas as issues de microsoft/mssql-python
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
aws-samples/sample-per-model-bedrock#243 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
FuRongJun-1999/dsh-memory#404 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
bug frontend
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
PennyLaneAI/catalyst#3337 ·
Mantenedores costumam responder em até 1 dia
-
Workflow.schedule stops when a cron deadline passes before sleepTalvez já em andamento @HuaTNA assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia