ADO.Net Async with Transactions... A Lesson Learned
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDpcXmdoG_ne0Yk3t4ZCVd3SaokP5TEEimbumOOeYi9THnc30i6OiEKKYeLS1JfXCe3kJy0M9BOvDbKEsmF7p0uxvo9Mqc8icRTcgK0ulmJPh7uen0L_s7UNz5y_fCEARCI6V0LV4jcr4/s640/Uh+Oh.png)
Last night I was testing out a new WebApi Filter I've added to a project, its fairly simple, log some data that comes from a HTTP header to the DB. This particular project has no Entity Framework or anything, just simple ADO.Net, in fact I think the project has 3 stored proc's in total. I tend to Async all the things by default so when I originally wrote my DB code I had: using (var conn = new SqlConnection(_connectionString)) { await conn.OpenAsync(); using (var transaction = conn.BeginTransaction()) { var command = conn.CreateCommand(); command.CommandText = "[Api].[LogDeviceRequest]"; command.CommandType = System.Data.CommandType.StoredProcedure; command.Transaction = transaction; command.Parameters.AddWithValue(//etc try { await command.ExecuteNonQueryAsync(); } catch { transaction.Rollback();