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 e As Exception
Console.WriteLine(e.Message)
Finally
myconnection1.Close()
myconnection2.Close()
End Try
End Sub
End Class
Related examples in the same category