Search notes:

SQL Server function: xact_state

xact_state() can be used to determine if a session (?) has an active transaction.
It returns 0 if no transaction is active and 1 if one is active.
If there is an active transaction which caused an error, it returns -1.
set nocount on;

create table tq84_xact_state(col int);

select 'xact_state = ' + str(xact_state(), 2);
--
-- xact_state =  0
--

begin transaction;

select 'xact_state = ' + str(xact_state(), 2);
--
-- xact_state =  1
--

insert into tq84_xact_state values (1);

commit;

select 'xact_state = ' + str(xact_state(), 2);
--
-- xact_state =  0
--

drop table tq84_xact_state;

go
Github repository about-MSSQL, path: /t-sql/functions/xact_state.sql

See also

T-SQL functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1740462713, '3.15.179.238', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/SQL-Server/T-SQL/functions/xact_state(74): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78