Exemplo n.º 1
0
 /// <inheritdoc/>
 public override void MakeSavepoint(string name)
 {
     EnsureIsNotDisposed();
     EnsureTransactionIsActive();
     activeTransaction.Save(name);
 }
Exemplo n.º 2
0
        /***********************************************************
         * The purpose of this method is to perform DML operations
         * on database table and create intermediate Savepoints.
         **********************************************************/
        private Boolean createSavepoints()
        {
            try
            {
                // Calling BeginTransaction on OracleConnection object
                // creates an OracleTransaction object
                myTransaction = conn.BeginTransaction();
                Console.WriteLine("Transaction Started");

                OracleCommand cmd = new OracleCommand();
                cmd.Connection = conn;

                // DML operation # 1: without any Savepoint
                string cmdText1 = " INSERT INTO Products (Product_id, Product_name)" +
                                  " VALUES (1,'Product 1')";
                cmd.CommandText = cmdText1;
                cmd.ExecuteNonQuery();

                Console.WriteLine("Inserted data for Product 1");
                Console.WriteLine("");


                // Create Savepoint 'a'
                myTransaction.Save("a");
                Console.WriteLine("Created Savepoint a");

                // DML operation # 2: In Savepoint 'a'
                string cmdText2 = " INSERT INTO Products (Product_id, Product_name) " +
                                  " VALUES (2,'Product 2 ')";
                cmd.CommandText = cmdText2;
                cmd.ExecuteNonQuery();

                Console.WriteLine("Inserted data for Product 2");
                Console.WriteLine("");


                // Create Savepoint 'b'
                myTransaction.Save("b");
                Console.WriteLine("Created Savepoint b");

                // DML operation # 3: In Savepoint 'b'
                string cmdText3 = " INSERT INTO Products (Product_id, Product_name) " +
                                  " VALUES (3,'Product 3')";
                cmd.CommandText = cmdText3;
                cmd.ExecuteNonQuery();

                Console.WriteLine("Inserted data for Product 3");
                Console.WriteLine("");


                // Create Savepoint 'c'
                myTransaction.Save("c");
                Console.WriteLine("Created Savepoint c");

                // DML operation # 4: In Savepoint 'c'
                string cmdText4 = " INSERT INTO Products (Product_id, Product_name) " +
                                  " VALUES (4,'Product 4')";
                cmd.CommandText = cmdText4;
                cmd.ExecuteNonQuery();
                Console.WriteLine("Inserted data for Product 4");
                Console.WriteLine("");

                // Release all resources held by OracleCommand Object
                cmd.Dispose();

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Execution Failed" + ex);
                conn.Close();
                conn.Dispose();
                return(false);
            }
        }