Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
--Brad--
Contributor II
Contributor II

How to get the MSSQL Transaction_ID

I am trying to tie the Qlik Replicate change table to data in SQL Audit on MS SQL Server.  I thought I would be able to do this with the transaction_id in Qlik Replicate, but that transaction_id does not match the transaction_id generated by MS SQL.

Qlik's is alphanumeric where SQL's is numeric only.  I read in the Qlik Replicate documentation that The actual value is a hex-string of the 128-bit transaction ID." but when I decode Qlik's transaction_id, it still is not similar to what is in SQL:

2022-01-27 09_28_53-_C__Users_bcrandell_Downloads_20220127-140703359.csv - Notepad++.png

Are these totally different transaction_ids?  Am I just decoding it incorrectly?  Can I get the SQL transaction_id some other way? 

Thanks!
Brad

Labels (3)
1 Solution

Accepted Solutions
john_wang
Support
Support

Hello @--Brad-- ,

This is really a good question. Per my researching:

1. I'm afraid there is not an explicit mapping between transaction_id (in sys.dm_tran_database_transactions or other similar views) and [Transaction ID] (in TLOG, or say in fn_dblog() ). You cannot convert from one to another by a formula or vice versa because they are totally different things.

    However we can find their relationship, I will describe in detailed below.

2. In Replicate, we use  [Transaction ID] which gets from TLOG.

    This is what you see in column "header__transaction_id".

3. Personally I do not think you can use transaction_id  for your SQL Audit purpose, at least it's hard to use because it restarts at 0 after a server restart.

 

How to find out header__transaction_id by transaction_id 

  • Get transaction_id from active transactions:

 

select * from sys.dm_tran_database_transactions WHERE  database_id = DB_ID();

 

        In my sample, the transaction_id is 18129.

  • Get the [Transaction ID] from TLOG by using transaction_id 18129

 

SELECT [Transaction ID]
FROM   sys.fn_dblog(NULL, NULL)
WHERE  [Xact ID] = 18129;

 

        In my sample the [Transaction ID] is '0000:000016e6'

  • Get other information from TLOG by using [Transaction ID]

 

SELECT *                                  
FROM   sys.fn_dblog(NULL, NULL)           
WHERE  [Transaction ID] = '0000:000016e6';

 

        In Replicate target table the header__transaction_id looks like: E6160000000000000000000000000000

Hope this helps.

Regards,

John.

Help users find answers! Do not forget to mark a solution that worked for you! If already marked, give it a thumbs up!

View solution in original post

5 Replies
john_wang
Support
Support

Hello @--Brad-- ,

This is really a good question. Per my researching:

1. I'm afraid there is not an explicit mapping between transaction_id (in sys.dm_tran_database_transactions or other similar views) and [Transaction ID] (in TLOG, or say in fn_dblog() ). You cannot convert from one to another by a formula or vice versa because they are totally different things.

    However we can find their relationship, I will describe in detailed below.

2. In Replicate, we use  [Transaction ID] which gets from TLOG.

    This is what you see in column "header__transaction_id".

3. Personally I do not think you can use transaction_id  for your SQL Audit purpose, at least it's hard to use because it restarts at 0 after a server restart.

 

How to find out header__transaction_id by transaction_id 

  • Get transaction_id from active transactions:

 

select * from sys.dm_tran_database_transactions WHERE  database_id = DB_ID();

 

        In my sample, the transaction_id is 18129.

  • Get the [Transaction ID] from TLOG by using transaction_id 18129

 

SELECT [Transaction ID]
FROM   sys.fn_dblog(NULL, NULL)
WHERE  [Xact ID] = 18129;

 

        In my sample the [Transaction ID] is '0000:000016e6'

  • Get other information from TLOG by using [Transaction ID]

 

SELECT *                                  
FROM   sys.fn_dblog(NULL, NULL)           
WHERE  [Transaction ID] = '0000:000016e6';

 

        In Replicate target table the header__transaction_id looks like: E6160000000000000000000000000000

Hope this helps.

Regards,

John.

Help users find answers! Do not forget to mark a solution that worked for you! If already marked, give it a thumbs up!
--Brad--
Contributor II
Contributor II
Author

Thanks @john_wang ,

I see the relationship that you are talking about  and have been able to trace the lineage from Replicate's header__transaction_id to the transaction_id that's in SQL Audit.  I am working through how I would do this in a production scenario and my options don't seem ideal so far.

2022-02-01 10_54_54-SQLQuery12.sql - XAISQL841.TEMP_MARQUIS_20220113143213743_BCRANDELL (HCHBCORP_bc.png

 

I am wondering:  Is there any way to get Qlik Replicate to capture the XACT_ID (ie: transaction_id from SQL Audit) that is in the LDF file at the same time it is importing the rest of the data changes?

Thanks,
Brad

john_wang
Support
Support

Hello @--Brad-- ,

I was in public holiday in the past week. Sorry for the delay.

I'm afraid we are unable to get XACT_ID from TLOG in current Replicate versions yet. you may find all the header information by enable the store changes table. Please raise Feature Request in Suggest an Idea area if you really need it.

Regards,

John.

Help users find answers! Do not forget to mark a solution that worked for you! If already marked, give it a thumbs up!
john_wang
Support
Support

Hello @--Brad-- ,

Noticed you opened an idea article Capture XACT ID transaction ID during MS SQL Replication . Let's wait for PM team update.

Thank you,

John.

Help users find answers! Do not forget to mark a solution that worked for you! If already marked, give it a thumbs up!
--Brad--
Contributor II
Contributor II
Author

Thank you, @john_wang.