Advertisement
Guest User

Untitled

a guest
May 12th, 2012
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using Npgsql;
  4. using System.Transactions;
  5.  
  6. public class TransactionExample
  7. {
  8.  
  9.     public static void Main(String[] args)
  10.     {
  11.  
  12.             string connectionString = "Server=127.0.0.1;User id=npgsql_tests;password=npgsql_tests;Enlist=true";
  13.             using (TransactionScope tx = new TransactionScope())
  14.             {
  15.                 using (NpgsqlConnection connection = new
  16. NpgsqlConnection(connectionString))
  17.                 {
  18.                     connection.Open();
  19.                     using (NpgsqlCommand command = new
  20. NpgsqlCommand("insert into tablea (cola) values ('b')", connection))
  21.                     {
  22.                         command.ExecuteNonQuery();
  23.                     }
  24.                     using (NpgsqlConnection connection2 = new
  25. NpgsqlConnection(connectionString))
  26.                     {
  27.                         connection2.Open();
  28.                         using (NpgsqlCommand command = new
  29. NpgsqlCommand("insert into tablea (colb) values ('c')", connection2))
  30.                         {
  31.                             command.ExecuteNonQuery();
  32.                         }
  33.                     }
  34.                 }
  35.                 tx.Complete();
  36.             }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement