客户端-服务器应用程序VB.Net 2008 [英] Client-Server Application VB.Net 2008

查看:225
本文介绍了客户端-服务器应用程序VB.Net 2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在开发一个应用程序,其数据库将存储在服务器计算机上,并且客户端将访问该数据库.以下是我用于从数据库检索数据的代码.

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.

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



我对此代码有些困惑.让我们假设3个用户一次访问相同的数据,其中一个用户同时更改数据.然后其他2个用户将处理旧数据,而不是新数据.关于此的任何建议/解决方案请告诉我.

Thankx



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

推荐答案

由于数据集是断开连接的实体,因此无法避免这种情况.没有机制可以使数据保持活动"状态,而是可以观察到三个独立的副本.传统方法(谷歌的乐观锁定")是,如果一个用户更改了数据,则当第二个用户尝试更改相同的数据时,更改被拒绝,并且用户自读取数据以来就通知该数据已更改) .唯一的选择是建立某种过程来监控数据并在发生更改时通知所有用户,但这是困难的,资源昂贵,并且通常被认为是不切实际的.

另一种方法(请参阅悲观锁定")是在另一个表中维护锁定"记录,该记录将第一个用户读取的记录标记为对后续用户只读".乐观锁定通常不被使用,因为通常大多数用户只是读取一个公共集而不会更改相同的数据记录.
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.


这篇关于客户端-服务器应用程序VB.Net 2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆