Connection keeps open transaction (open_transaction_count) after connection.commit - works as intended?
@sumitmsft is already working on this.
Since Sep 9, 2026.
Assessment
This issue has not been assessed yet.
Description
Hello,
when using mssql-python we observed that it does not seem to close/commit all transactions.
For example with this script:
with mssql_python.connect(conn_string) as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT * FROM People")
print("wait here with debugger")
Before the application exits we see open transactions with this:
SELECT
s.session_id,
s.login_time,
s.host_name,
s.program_name,
s.login_name,
s.last_request_end_time,
c.most_recent_sql_handle,
s.open_transaction_count,
r.*
FROM sys.dm_exec_sessions s
LEFT JOIN sys.dm_exec_requests r
ON r.session_id = s.session_id
LEFT JOIN sys.dm_exec_connections c
ON c.session_id = s.session_id
WHERE s.open_transaction_count > 0
Is this intended behavior? The opened transaction does not seem to block any resources.
When doing a manual commit cursor.execute("IF @@TRANCOUNT > 0 COMMIT TRANSACTION") the transactions are closed properly before the application exits.
- Dominant language
- Python
- Stars
- 473
- Forks
- 60
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 36
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/mssql-python
-
area: bulk-copy bug triage done
microsoft/mssql-python#750 · 4 comments · 1 assignee ·
-
announcement
microsoft/mssql-python#748 · 1 assignee ·
-
area: connectivity-auth bug triage needed
Difficulty 4/5 3-5 days Newbie friendliness 62/100
microsoft/mssql-python#746 · 1 comment ·
-
area: data-types bug triage done
Difficulty 4/5 3-5 days Newbie friendliness 48/100
microsoft/mssql-python#745 · 1 comment ·
-
area: packaging-platform bug dependency: external triage done
microsoft/mssql-python#685 · 2 comments · 1 assignee ·
All issues in microsoft/mssql-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100