代码看起来像这样;
sqlConnection cn1 = new sqlConnection();cn1.Open(); //connection opened when there is no ambient transaction.... using(TransactionScope scope = new TransactionScope()){ sqlCommand cmd; //a typical sql command. ... cmd.ExecuteNonQuery(); //Is this command within transaction? ...}
这可以在连接上方的注释中找到.在this MSDN示例中打开.