Determine if SqlTransaction was written or only read

I am going to start by saying that I am sure that this is not possible. Googling did not find out who is asking this question, so I pessimistically hope so.

I use SqlTransaction to connect to the database and allow multiple consumers to use this transaction before closing it. Is it possible to determine if a transaction was used only for reading data or for reading / writing data, even if stored procedures could be used? Is there any SQL property or method (other than making any non-human difference) that can verify this?

+4
source share
3 answers

sys.dm_exec_sessions writes. :

SELECT writes FROM sys.dm_exec_sessions WHERE session_id = @@SPID

. , DMV O(N) . . , .

, . ( SqlConnection), . .

+3

sys.dm_ .

, ( ), , - , .

... SPID.

USE tempdb
begin tran
create table dave (id int)
insert into dave (id) select 1
-- rollback tran

, ( spid):

select database_transaction_log_bytes_used, *
from sys.dm_tran_database_transactions dt 
inner join sys.dm_tran_active_transactions at on (at.transaction_id = dt.transaction_id)   
inner join sys.dm_tran_session_transactions st on (st.transaction_id = dt.transaction_id) 
where (dt.database_id = DB_ID('tempdb')) and (st.is_user_transaction=1) 
and session_id=83

.

:

USE tempdb
begin tran
select getdate()
-- rollback tran

sys.dm_...

, -. .

.

, proc/view, , , spid ( SELECT @@SPID), .

+2

mmm, This is only an idea. - : , CountRead CountWrite, , SELECT if - INSERT - . , , ( , ).

, SELECT , , , , , , .

, .;) , , , , .

0
source

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


All Articles