public void run()
        {
            Exception exp = null;

            OleDbConnection con = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);

            con.Open();

            /*********************************************************
             * OLEDB Provider for SQL Server does not allow nested transactions
             * http://support.microsoft.com/kb/177138/EN-US/
             * http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q316872&
             */
            if ((ConnectedDataProvider.GetDbType(con) == DataBaseServer.SQLServer) ||
                (ConnectedDataProvider.GetDbType(con) == DataBaseServer.Oracle) ||
                (ConnectedDataProvider.GetDbType(con) == DataBaseServer.PostgreSQL) ||
                (ConnectedDataProvider.GetDbType(con) == DataBaseServer.DB2))
            {
                Log(string.Format("Test skipped, nested transactions are not supported in {0}", ConnectedDataProvider.GetDbType(con)));
                return;
            }

            // How To Implement Nested Transactions with Oracle
            // http://support.microsoft.com/kb/187289/EN-US/

            OleDbTransaction txnOuter = null;
            OleDbTransaction txnInner = null;

            try
            {
                BeginCase("Check Outer Transaction Isoloation Level");

                txnOuter = con.BeginTransaction();
                txnInner = txnOuter.Begin();

                Compare(txnOuter.IsolationLevel, IsolationLevel.ReadCommitted);
            }
            catch (Exception ex) { exp = ex; }
            finally{ EndCase(exp); exp = null; }

            try
            {
                BeginCase("Check Inner Transaction Isoloation Level");
                Compare(txnOuter.IsolationLevel, IsolationLevel.RepeatableRead);
            }
            catch (Exception ex) { exp = ex; }
            finally{ EndCase(exp); exp = null; }

            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
Esempio n. 2
0
        private void ModeThree()
        {
            OleDbConnection connection = new OleDbConnection();

            connection.ConnectionString = @"Provider=Microsoft.ACE.OleDb.12.0;Data Source=C:\Users\nwarke\Desktop\NickDb.accdb";

            String query1 = "Select * from Employee";
            String query2 = "Select * from [Order]";


            OleDbCommand command = new OleDbCommand();

            command.Connection  = connection;
            command.CommandText = "Insert into Employee (id, name, age, salary ,company) values(@id, @name, @age, @salary ,@company)";
            command.Parameters.AddWithValue("@id", 50);
            command.Parameters.AddWithValue("@name", "OKU;");
            command.Parameters.AddWithValue("@age", 30);
            command.Parameters.AddWithValue("@salary", 3046);
            command.Parameters.AddWithValue("@company", "Gopu");


            DataSet dataSet = new DataSet();

            connection.Open();
            OleDbTransaction transaction = connection.BeginTransaction();;
            OleDbCommand     command2    = new OleDbCommand(query2, connection, transaction);

            try
            {
                transaction.Begin();
                Console.WriteLine("Rows update - {0}", command.ExecuteNonQuery());
                transaction.Commit();
                //dataGridEmployee.DataSource = dataSet.Tables[0];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                transaction.Rollback();
            }
        }