question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can we trace BeginTransaction(), RollbackTransaction() and CommitTransaction()?

See original GitHub issue

Discussed in https://github.com/linq2db/linq2db/discussions/3073

<div type='discussions-op-text'>

Originally posted by ww9 June 24, 2021 Hi, I’ve been trying to log SQL queries like this and it works but it doesn’t tell me about transactions which are important to my log.

Environment details

linq2db version: Release 4.0.0-preview.1 Database Server: MariaDB 10.4 Database Provider: MySql.Data 8.0.25 Operating system: Windows 10 x64 .NET Framework: .NET 5.0

Trace setup

LinqToDB.Data.DataConnection.TraceSwitch.Level = TraceLevel.Verbose;
LinqToDB.Data.DataConnection.OnTrace = (TraceInfo info) =>
{
   System.Diagnostics.Debug.WriteLine("\n\n" + info.Operation.ToString() + "." 
      + info.TraceInfoStep + " @@@@@@@@@@@@@@@@\n" + info.SqlText);
};
LinqToDB.Data.DataConnection.TurnTraceSwitchOn();

Application code

db.BeginTransaction();
db.UserAgent.Value(u => u.Hash, "hash").Value(u => u.AgentString, "agent").Insert();
db.RollbackTransaction();

Output (missing any information about transactions):

ExecuteNonQuery.BeforeExecute @@@@@@@@@@@@@@@@
-- Default MySql.Official MySql
DECLARE @Hash VarChar(4) -- String
SET     @Hash = 'hash'
DECLARE @AgentString VarChar(5) -- String
SET     @AgentString = 'agent'

INSERT INTO `app`.`user_agent`
(
	`Hash`,
	`AgentString`
)
VALUES
(
	@Hash,
	@AgentString
)

ExecuteNonQuery.AfterExecute @@@@@@@@@@@@@@@@
-- Default MySql.Official MySql
DECLARE @Hash VarChar(4) -- String
SET     @Hash = 'hash'
DECLARE @AgentString VarChar(5) -- String
SET     @AgentString = 'agent'

INSERT INTO `app`.`user_agent`
(
	`Hash`,
	`AgentString`
)
VALUES
(
	@Hash,
	@AgentString
)

DisposeQuery.Completed @@@@@@@@@@@@@@@@
-- Default MySql.Official MySql
DECLARE @Hash VarChar(4) -- String
SET     @Hash = 'hash'
DECLARE @AgentString VarChar(5) -- String
SET     @AgentString = 'agent'

INSERT INTO `app`.`user_agent`
(
	`Hash`,
	`AgentString`
)
VALUES
(
	@Hash,
	@AgentString
)

How can I trace transaction start, rollback and commit?

</div>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
MaceWinducommented, Jun 25, 2021

Also there are Async versions of those API - they should be also logged

1reaction
MaceWinducommented, Jun 25, 2021

@vw9, btw, if you will send PR, introduce new TraceOperation entries for begin/commit/rollback

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do detect that transaction has already been started?
The next beginTransaction() increments the level to 0, which means the transaction can neither be rolled back nor committed.
Read more >
How to rollback using explicit SQL Server transactions
Check current identity value using the IDENT_CURRENT() function; It begins an explicit transaction using the BEGIN TRANSACTION statement ...
Read more >
Transaction in Entity Framework 6 & Core
In Entity Framework, the SaveChanges() method internally creates a transaction and wraps all ... perform CRUD operations and then commit each transaction.
Read more >
Tracking the successful/un-successful execution of T-SQL ...
ROLLBACK TRANSACTION ;. SELECT 'The transaction is in an uncommittable state.' + ' Rolling back transaction.'.
Read more >
Transactions with Memory-Optimized Tables - SQL Server
Accesses a memory-optimized table from interpreted Transact-SQL; or; Executes a native proc when a transaction is already open (XACT_STATE() = 1) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found