Isolation Level ReadUncommitted : Transaction « Database ADO.net « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Database ADO.net » TransactionScreenshots 
Isolation Level ReadUncommitted
Isolation Level ReadUncommitted

Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Data


Public Class MainClass
    
    Shared Sub Main()
        Dim myconnection1, myconnection2 As SqlConnection
        Dim mycommand1, mycommand2 As SqlCommand
        Dim mytransaction1, mytransaction2 As SqlTransaction
        Dim myreader As SqlDataReader
        Dim ConnectionString As String

        'open a database connection
        ConnectionString = "Server=(local)\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=SSPI"
        myconnection1 = New SqlConnection(ConnectionString)
        myconnection2 = New SqlConnection(ConnectionString)

        Try
            myconnection1.Open()
            myconnection2.Open()

            'start a transaction
            mytransaction1 = myconnection1.BeginTransaction()
            mytransaction2 = myconnection2.BeginTransaction(IsolationLevel.ReadUncommitted)

            mycommand1 = New SqlCommand()
            mycommand1.Connection = myconnection1
            mycommand1.Transaction = mytransaction1

            mycommand2 = New SqlCommand()
            mycommand2.Connection = myconnection2
            mycommand2.Transaction = mytransaction2


            mycommand1.CommandText = "insert into Employee  values (101, 'F', 'L')"
            mycommand1.ExecuteNonQuery()
            mycommand1.CommandText = "insert into Employee values (101, 'F', 'L')"
            mycommand1.ExecuteNonQuery()

            mycommand2.CommandText = "select * from Employee"
            myreader = mycommand2.ExecuteReader()
            Console.WriteLine("Last 2 Orders - Transaction is pending")
            Console.WriteLine("======================================")
            While myreader.Read()

                Console.WriteLine(myreader.GetInt32(0))
            End While
            myreader.Close()
            Console.ReadLine()

            mytransaction1.Rollback()
            mycommand2.CommandText = "select * from Employee"
            myreader = mycommand2.ExecuteReader()

            Console.WriteLine("Last 2 Orders - Transaction rolled back")
            Console.WriteLine("=======================================")
            While myreader.Read()
                Console.WriteLine(myreader.GetInt32(0))
            End While
            Console.ReadLine()
        Catch As Exception
            Console.WriteLine(e.Message)
        Finally
            myconnection1.Close()
            myconnection2.Close()
        End Try
    End Sub
End Class



           
       
Related examples in the same category
1.Simple Transaction Commit and RollBack: SqlTransaction has completed; it is no longer usable.Simple Transaction Commit and RollBack: SqlTransaction has completed; it is no longer usable.
2.Transaction save point and roll back
3.Transaction Rollback Demo
4.Transaction Commit Demo
5.DataSet transactionDataSet transaction
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.