Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working on an application whose data base will be stored on a server computer and the clients will be accessing that db. Following is the code which i use to retrieve data from data base.

VB
Protected Function ExecuteDQL(ByVal Query As String) As DataSet        
       DS = New DataSet        
       DBCom = DBCon.CreateCommand()                
       DBAdp = New SqlDataAdapter        
       Try
            DBCom.CommandText = Query            
            DBCom.Connection = DBCon            
            DBAdp.SelectCommand = DBCom            
            DBAdp.Fill(DS)            
            If DS.Tables(0).Rows.Count >= 1 Then
                Return DS            
            Else
                Return Nothing
            End If
      Catch ex As Exception            
            MsgBox(ex.Message)  
            Return Nothing          
      Finally
            CloseDB()        
      End Try
    End Function


I have a little confusion about this code. Lets assume 3 users access same data at a time and one of them changes data meanwhile. Then other 2 users will be dealing with the old data not the new one. Any suggestion/solution about this please do tell me.

Thankx
Posted
Updated 18-Mar-10 2:14am
v2

1 solution

Since datasets are disconnected entities, there is no way to avoid this. No mechanism exists to keep the data "live", instead there are three independant copies, as you observe. The traditional approach (google "optimistic locking") is that if the data is changed by one user, then when the second attempts to change the same data, the change is rejected and the user notified that the data has changed since he read it). The only alternative would be to set up some process to monitor the data and notify all users when a change occurred, but that is difficult, resource expensive, and generally regarded as impractical.

Another approach (see "pessimistic locking") is to maintain "lock" records in another table, that mark the records read by the first user as "read only" to subsequent users. This is not used a frequently as optimistic locking, since it is usually the case that most users just read a common set but don't change the same data records.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900