This is related to the Nested Database transactions in C#.
The objects in collection I want to take in transaction implement their own transactions using SqlConnection.BeginTransaction method.
After reading this post I am not sure if I can mix those too or not. I am using SQL Server 2005 and each object uses connection details from static configuration class.
Does anybody have experience with this ?
Here is the sample code:
using(TransactionScope scope = new TransactionScope())
{
for (int i=0; i<=1000....)
{
SqlConnection con = new SqlConnection()
SqlCommand cmd = new SqlCommand("delete from ...", con);
try {
con.Open();
DbTransaction t = con.BeginTransaction();
cmd.ExecuteNonQuery();
...
cmd.CommandText = .... ;
cmd.ExecuteNonQuery();
t.Commit ...
}
catch {
t.Rollback ...
}
con.Close()
}
}
Thx