Guest User

Untitled

a guest
Oct 16th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. public class DbCommandExample
  2. {
  3. public void Execute(string connectionString)
  4. {
  5. using (var conn = new SqlConnection(connectionString))
  6. {
  7. var rnd = new Random();
  8. var trx = $"transaction#{rnd.Next()}";
  9.  
  10. conn.Open();
  11.  
  12. using (var trans = conn.BeginTransaction(IsolationLevel.Serializable, trx))
  13. {
  14. using (var cmd = new SqlCommand("Select * from Sales.Invoices", conn, trans))
  15. {
  16. cmd.ExecuteNonQuery();
  17. }
  18.  
  19. trans.Commit();
  20. }
  21. }
  22. }
  23. }
Add Comment
Please, Sign In to add comment