Run SQL Kill from Python

I always retrieve data from a Python SQL database through pymssql, which can lead to too much connection downtime. Therefore, I am writing an SQL procedure to kill idle connections, and it works when I start SSMS. However, when I try to execute it in python, it fails and raises:

(6115, b'KILL command cannot be used inside user transactions .DB-Lib error message 20018, severity 16: \ nGeneral SQL Server error: check messages from SQL Server \ n ')

The following code is a method to execute an SQL procedure from python,

import pymssql

conn = pymssql.connect(server, username, password, dbname)
cursor = conn.cursor()

cursor.execute("exec killconn")

How can I handle this?

Thank you very much.

+4
source share

Source: https://habr.com/ru/post/1675300/


All Articles