Results 1 to 2 of 2

Thread: sqltransaction locking record for all isolation levels

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Malaysia
    Posts
    64

    sqltransaction locking record for all isolation levels

    I'm testing out the sqltransaction and everything was working fine but when I tried opening another connection to read the record before the values are commited, it seems to be locked even though I set the isolationlevel for the transaction to be ReadUncommited.

    The result is the program will hang when the second connection tries to read from the same record that was being updated by the transaction.

    If there any way to get around this? I want to be able to at least read the uncommited changes.

    Code:
            Dim cn As New SqlClient.SqlConnection(strCn)
    
            Dim cn2 As New SqlClient.SqlConnection(strCn)
    
            cn.Open()
            cn2.Open()
    
            Dim cmd As New SqlClient.SqlCommand()
            Dim tran As SqlClient.SqlTransaction = cn.BeginTransaction(IsolationLevel.ReadUncommitted)
            MsgBox(tran.IsolationLevel.ToString)
    
            cmd.CommandType = CommandType.Text
            cmd.Transaction = tran
            cmd.CommandText = "INSERT INTO [Sales] (ItemNo,TransNo,Quantity) VALUES (1,1,10)"
            cmd.Connection = cn
            cmd.ExecuteNonQuery()
    
            cmd.CommandText = "UPDATE [Stock] SET Quantity=Quantity-10 WHERE ItemNo=1"
            cmd.ExecuteNonQuery()
    
            Dim cmd2 As New SqlClient.SqlCommand()
            cmd2.CommandType = CommandType.Text
            cmd2.Connection = cn2
            cmd2.CommandText = "SELECT * FROM [Stock] WHERE ItemNo=1"

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Malaysia
    Posts
    64
    btw i am using the sqldatareader to get the record back

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width