For a project I'm writing a bunch of queries, which are in it's own separately, but they need to be executed in a transaction.
I'm using a TransactionScope
Consider the following code:
// connection = new SqlConnection(...);
// connection.Open();
using(var transactionScope = new TransactionScope())
{
// execute first query on connection
using(var sqlCommand = new SqlCommand("DELETE THIS", connection))
{
// sqlCommand.Parameters....
sqlCommand.ExecuteNonQuery();
}
// second query
using(var sqlCommand = new SqlCommand("INSERT THAT", connection))
{
// sqlCommand.Parameters....
sqlCommand.ExecuteNonQuery();
}
transactionScope.Complete();
}
Now how does the sqlCommand
know that somewhere in previous code I have a transactionScope
?