Skip to main content

280 posts tagged with "C#"

C# Programming Language

View All Tags

Fixed: "Connection must be valid and open to rollback transaction" with MySql.Data

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

My log said Connection must be valid and open to rollback transaction, and that wasn't what had gone wrong. Something had failed after the commit, my catch tried to roll back a transaction that was already finished, and the new exception replaced the real one. The fix also removes code: you rarely need RollbackAsync at all.

Fixed: "The connection is already in a transaction and cannot participate in another transaction" in EF Core

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Calling one helper method from inside a transaction failed with The connection is already in a transaction and cannot participate in another transaction. The helper had its own BeginTransactionAsync, which made sense when it was written, and it stopped making sense once something else called it inside a transaction.

Fixed: Two Requests Buy the Last Item in EF Core (Overselling)

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

One unit left, five simultaneous orders, and all five answered 201 Created. The order code was in a transaction, and it checked the stock first. It looked correct, and the first time I ran it, it even behaved. The check and the write were two separate steps, and every order did the check before any of them had written.

Fixed: EF Core Retry Places the Same Order Twice After a Lost COMMIT

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

One request answered 201, and the database had two orders, with the stock taken twice. MySQL had committed the first attempt, the connection dropped before the reply arrived, and EF Core's retry, knowing only that the commit had failed, did it all again. Retrying is only safe when each attempt can tell that an earlier one already worked.

Fixed: "Too many connections" from "Authentication to host failed" with MySql.Data

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Authentication to host '127.0.0.1' for user 'inventory_app' using method 'caching_sha2_password' failed with message: Too many connections looks like a login problem, and I went to check the password first. The password was fine. The second half of the message is the real error: MySQL had no connections left to give.