How can we trace BeginTransaction(), RollbackTransaction() and CommitTransaction()?
See original GitHub issueDiscussed 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:
- Created 2 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Also there are Async versions of those API - they should be also logged
@vw9, btw, if you will send PR, introduce new
TraceOperation
entries for begin/commit/rollback