Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using Npgsql;
- using System.Transactions;
- public class TransactionExample
- {
- public static void Main(String[] args)
- {
- string connectionString = "Server=127.0.0.1;User id=npgsql_tests;password=npgsql_tests;Enlist=true";
- using (TransactionScope tx = new TransactionScope())
- {
- using (NpgsqlConnection connection = new
- NpgsqlConnection(connectionString))
- {
- connection.Open();
- using (NpgsqlCommand command = new
- NpgsqlCommand("insert into tablea (cola) values ('b')", connection))
- {
- command.ExecuteNonQuery();
- }
- using (NpgsqlConnection connection2 = new
- NpgsqlConnection(connectionString))
- {
- connection2.Open();
- using (NpgsqlCommand command = new
- NpgsqlCommand("insert into tablea (colb) values ('c')", connection2))
- {
- command.ExecuteNonQuery();
- }
- }
- }
- tx.Complete();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement