Currently working with Oracle, but will also need a solution for MS SQL.
I have a GUI that allows users to generate SQL that will be executed on the database. This
Oracle introduced ALTER SYSTEM CANCEL SQL
in 18c. You would need to add some kind of comment with UID to your SQL and then look for it something like this
SELECT S.SID||','||S.SERIAL#
FROM GV$SESSION S, V$SQL Q
WHERE S.USERNAME IS NOT NULL
AND S.STATUS = 'ACTIVE'
AND S.SQL_ID IS NOT NULL
AND Q.SQL_ID = S.SQL_ID
and sql_text like '%{queryId}%'
And then run another operation from .NET ALTER SYSTEM CANCEL SQL 'SID, SERIAL'