Results 1 to 3 of 3

Thread: concurrency violation??

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2004
    Posts
    43

    concurrency violation??

    Hi guys,

    I tried to search the forum on the topic 'concurrency violation' but I couldn't find much, so I make a new post of my problem.

    The problem is the following: I try to make a database application (access 2000) which can be simultaneously used by multiple users. I added a (simplified) sample so you can test it yourself if you want.

    I use a datagrid to show the contents of a datasource with only one table : tblTest. I used the dataadapter wizard to create the oledbdataadapter and I used the 'optimistic concurrency' setting in the wizard.

    If two users try to adapt the same field in het datagrid and the try to update it, then a dbexception is created which warns the user. This part works fine. After this message the user has to get two choices:
    1. view the changes (this is simple : refill the dataset)
    2. don't view the changes and update the datasource with the values he changed.

    Option 2 doesn't work : when the user selects this option I always get this message : concurrency violation , 0 rows affected.

    I assume this means there aren't any changes to the dataset, but this can't be because there are changes?

    PS: i simulate two simultaneous users by running two times the .exe

    What Am I doing wrong??

    Here is the code:

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.         Me.OleDbConnection1.Open()
    4.         Me.OleDbDataAdapter1.Fill(DStest, "tblTest")
    5.         Me.OleDbConnection1.Close()
    6.  
    7.         Me.DataGrid1.DataSource = DStest
    8.         Me.DataGrid1.DataMember = "tblTest"
    9.  
    10.     End Sub
    11.  
    12.  
    13.     Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
    14.         Dim messagestring As String
    15.         messagestring = "Data has been changed since you opened it.  Do you want to see the changes or update the datasource with your changes.  Click 'Ja' to view the changes; click 'Nee' to pass your changes to the datasource."
    16.  
    17.         Try
    18.             Me.BindingContext(DStest, "tblTest").EndCurrentEdit()
    19.             Me.OleDbDataAdapter1.Update(DStest, "tblTest")
    20.         Catch dbcEX As Data.DBConcurrencyException
    21.             Dim dResult As DialogResult
    22.             dResult = MessageBox.Show(messagestring, "There was a concurrency", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Error)
    23.             If dResult = DialogResult.Yes Then
    24.                 Me.DStest.Clear()
    25.                 OleDbConnection1.Open()
    26.                 Me.OleDbDataAdapter1.Fill(DStest, "tblTest")
    27.                 OleDbConnection1.Close()
    28.             ElseIf dResult = DialogResult.No Then
    29.                 'MsgBox(DAtest.UpdateCommand.ExecuteNonQuery.ToString)
    30.                 Me.OleDbDataAdapter1.Update(DStest, "tbltest")
    31.             End If
    32.  
    33.         End Try
    34.     End Sub

    In attachment you can find the code and the database. If you want to try it, but the database in your C:root.

    Many thanks
    Attached Files Attached Files

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