Results 1 to 18 of 18

Thread: [RESOLVED] [VS2008] Concurrency

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    New Orleans, LA
    Posts
    161

    Resolved [RESOLVED] [VS2008] Concurrency

    DBConcurrencyException was unhandled.
    Concurrency violation: the DeleteCommand affected 0 of the expected 1 records.
    Above is the error message received when doing the following:
    Using a binding source for the datagrid I populate textboxes for the row that is currently selected. The problem occurs when I modify one of these textboxes, then delete a different row, then save (in that order). The following are the two scripts used in this process, if you need more I'd be happy to supply them.

    Delete Script:
    Code:
        Private Sub cmdMCDeleteRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMCDeleteRecord.Click
    
            Dim PK As Integer = CInt(Me.dgvMyCigars.CurrentRow.Cells("ID").Value)
            Dim MCconnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\cdb.rmd;Persist Security Info=False;")
            Dim MCcommand As New OleDb.OleDbCommand("DELETE * FROM CigarTable WHERE ID = @ID", MCconnection)
    
            Try
    
                If MsgBox("Are you sure you wish to delete the current cigar?", MsgBoxStyle.YesNo, "eHumidor - Delete Record Confirmation") = MsgBoxResult.Yes Then
    
                    Me.MCBind.EndEdit()
                    DirectCast(Me.MCBind.Current, DataRowView).Delete()
                    Me.MCBind.EndEdit()
    
                    MCcommand.Parameters.AddWithValue("@ID", PK)
    
                    MCconnection.Open()
                    'Open Connection
                    MCcommand.ExecuteNonQuery()
                    MCconnection.Close()
    
                    Appstatus = "Cigar Successfully Deleted!"
                    Status()
    
                End If
    
            Catch ex As Exception
    
                Appstatus = "Error 004 - Cigar not deleted.  Please submit bug report!"
                Status()
                MsgBox(ex.Message)
    
            Finally
    
                If MCconnection.State = ConnectionState.Open Then
                    MCconnection.Close()
                End If
    
            End Try
    
        End Sub
    Save Script:
    Code:
            Try
                Dim MCCmdBldr As OleDbCommandBuilder
    
                Me.MCBind.EndEdit()
                MCCmdBldr = New OleDbCommandBuilder(Me.MCadapter)
                Debug.WriteLine(MCCmdBldr.GetUpdateCommand.CommandText())
                Me.MCadapter.Update(Me.MCDS, "CigarTable")
                Me.MCconnection.Close()
    
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
    I've read MSDN on concurrency errors and while I can make sense of what concurrency is, I cannot see why I'm having this problem.

  2. #2
    Fanatic Member onlyGirl's Avatar
    Join Date
    Sep 2006
    Location
    Houston, TX
    Posts
    743

    Re: [VS2008] Concurrency

    Try executing the delete command directly on the database, I'm assuming it's Access. It should help you out a little more. Make sure that the id is in the db.
    Using Visual Studio 2008

    Please mark your thread RESOLVED if you no longer need help.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    New Orleans, LA
    Posts
    161

    Re: [VS2008] Concurrency

    Do you mean opening the database and try using the same command that I used above? Otherwise, it seems to me (a novice at best) that I am deleting directly from the database using:

    Code:
    Dim MCcommand As New OleDb.OleDbCommand("DELETE * FROM CigarTable WHERE ID = @ID", MCconnection)
    No?

    Ok, after your suggestion I went back and tested again. Turns out you do not have to modify a record first, that was just coincidence. All I have to do is delete, using the script above (which succeeds, record gone from table and database), then save. On the save is the error, using the script above.
    Last edited by Minolwen; Jun 27th, 2008 at 02:01 PM.

  4. #4
    Fanatic Member onlyGirl's Avatar
    Join Date
    Sep 2006
    Location
    Houston, TX
    Posts
    743

    Re: [VS2008] Concurrency

    Yes, open the database and click on query's and try to execute the command there.

    But before you do that, I'm curious as to what will happen if you change the parameters to this:
    Code:
    MCcommand.Parameters.Add("@ID", OleDbType.Integer(specify the size here),"ID")
    Using Visual Studio 2008

    Please mark your thread RESOLVED if you no longer need help.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    New Orleans, LA
    Posts
    161

    Re: [VS2008] Concurrency

    Parameter @ID has no default value.
    I have tried both yours and mine:

    This is in place already:

    Code:
    Dim PK As Integer = CInt(Me.dgvMyCigars.CurrentRow.Cells("ID").Value)
    I have tried yours:
    Code:
    MCcommand.Parameters.Add("@ID", OleDbType.Integer, 5 ,"ID")
    and mine:

    Code:
    MCcommand.Parameters.Add("@ID", OleDbType.Integer, 5, PK.ToString)
    They all lead to the error at the top of this post, however the record in every situation, gets deleted from the database.

  6. #6
    Fanatic Member onlyGirl's Avatar
    Join Date
    Sep 2006
    Location
    Houston, TX
    Posts
    743

    Re: [VS2008] Concurrency

    Quote Originally Posted by Minolwen
    I have tried both yours and mine:

    This is in place already:

    Code:
    Dim PK As Integer = CInt(Me.dgvMyCigars.CurrentRow.Cells("ID").Value)
    I have tried yours:
    Code:
    MCcommand.Parameters.Add("@ID", OleDbType.Integer, 5 ,"ID")
    and mine:

    Code:
    MCcommand.Parameters.Add("@ID", OleDbType.Integer, 5, PK.ToString)
    They all lead to the error at the top of this post, however the record in every situation, gets deleted from the database.
    What is ID's datatype in the db?
    Using Visual Studio 2008

    Please mark your thread RESOLVED if you no longer need help.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    New Orleans, LA
    Posts
    161

    Re: [VS2008] Concurrency

    Ok, I ran:

    DELETE * FROM CigarTable WHERE ID = 243
    Ok, I picked a random ID that was in the table. But when I ran this in Access (07), I went back to the table and the row was there but said "DELETED" in every cell. I had to restart access for the row to actually be gone.

    Not sure if this helps.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    New Orleans, LA
    Posts
    161

    Re: [VS2008] Concurrency

    Long Integer.

  9. #9
    Fanatic Member onlyGirl's Avatar
    Join Date
    Sep 2006
    Location
    Houston, TX
    Posts
    743

    Re: [VS2008] Concurrency

    It has to do with the datatypes, I believe.

    Try executing the command in Access again but this time put 243 as '243'
    Using Visual Studio 2008

    Please mark your thread RESOLVED if you no longer need help.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    New Orleans, LA
    Posts
    161

    Re: [VS2008] Concurrency

    The action or event was blocked by disabled mode.
    Message at the bottom of the screen in access.

  11. #11
    Fanatic Member onlyGirl's Avatar
    Join Date
    Sep 2006
    Location
    Houston, TX
    Posts
    743

    Re: [VS2008] Concurrency

    Quote Originally Posted by Minolwen
    Message at the bottom of the screen in access.
    I've never had that error before but I did a search and this is what I found:
    http://office.microsoft.com/en-us/ac...564031033.aspx
    Using Visual Studio 2008

    Please mark your thread RESOLVED if you no longer need help.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    New Orleans, LA
    Posts
    161

    Re: [VS2008] Concurrency

    Data type mismatch in criteria expression.
    Now that I am trusted by myself, I ran it again and the above error is what I received.

  13. #13
    Fanatic Member onlyGirl's Avatar
    Join Date
    Sep 2006
    Location
    Houston, TX
    Posts
    743

    Re: [VS2008] Concurrency

    Quote Originally Posted by Minolwen
    Now that I am trusted by myself, I ran it again and the above error is what I received.
    Like I said, it has to do with the way you declared ID. Try messing with the different options of Number.
    Using Visual Studio 2008

    Please mark your thread RESOLVED if you no longer need help.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    New Orleans, LA
    Posts
    161

    Re: [VS2008] Concurrency

    Well, I appreciate the help. I'm not getting a concurrency error anymore, in fact I've been messing with it trying to figure it out and search google/msdn so much I'm not sure when that error went away.

    Now the only error I get is the:

    Parameter @ID has no default value.
    However the record still deletes and the program does not stop, just displays that error message (probably due to the Try statement it is wrapped in ).

  15. #15
    Fanatic Member onlyGirl's Avatar
    Join Date
    Sep 2006
    Location
    Houston, TX
    Posts
    743

    Re: [VS2008] Concurrency

    Put a breakpoint at the parameter and hover over textbox1 to check the value.
    Using Visual Studio 2008

    Please mark your thread RESOLVED if you no longer need help.

  16. #16
    Fanatic Member onlyGirl's Avatar
    Join Date
    Sep 2006
    Location
    Houston, TX
    Posts
    743

    Re: [VS2008] Concurrency

    Quote Originally Posted by Minolwen
    Well, I appreciate the help. I'm not getting a concurrency error anymore, in fact I've been messing with it trying to figure it out and search google/msdn so much I'm not sure when that error went away.

    Now the only error I get is the:



    However the record still deletes and the program does not stop, just displays that error message (probably due to the Try statement it is wrapped in ).
    The error went away because you changed disabled mode. If you need more help, you can PM me.
    Using Visual Studio 2008

    Please mark your thread RESOLVED if you no longer need help.

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    New Orleans, LA
    Posts
    161

    Re: [VS2008] Concurrency

    Sometimes the amount of ignorance I shed in a day amazes me. I was deleting the record twice (three times depending on how you see it)...

    Code:
    DirectCast(Me.MCBind.Current, DataRowView).Delete()
    Marked it for deleting via the binding source... (You probably see where I'm going already)

    Code:
    MCcommand.ExecuteNonQuery()
    Deleted it from the database.

    Then finally updating on exit attempted to delete it again because of the binding source. So I commented out the delete directly from the database, kept the first code above and it deletes on exit now.

    Haven't determined if this is the best method which is why I only commented it out and not deleted it. Will consider the rest of the app before going further. I do greatly appreciate your help though, thank you.

  18. #18
    Fanatic Member onlyGirl's Avatar
    Join Date
    Sep 2006
    Location
    Houston, TX
    Posts
    743

    Re: [VS2008] Concurrency

    Quote Originally Posted by Minolwen
    Sometimes the amount of ignorance I shed in a day amazes me. I was deleting the record twice (three times depending on how you see it)...

    Code:
    DirectCast(Me.MCBind.Current, DataRowView).Delete()
    Marked it for deleting via the binding source... (You probably see where I'm going already)

    Code:
    MCcommand.ExecuteNonQuery()
    Deleted it from the database.

    Then finally updating on exit attempted to delete it again because of the binding source. So I commented out the delete directly from the database, kept the first code above and it deletes on exit now.

    Haven't determined if this is the best method which is why I only commented it out and not deleted it. Will consider the rest of the app before going further. I do greatly appreciate your help though, thank you.
    Stick with ExecuteNonQuery. LOL, I can understand I've made mistakes like that. You're welcome.
    Using Visual Studio 2008

    Please mark your thread RESOLVED if you no longer need help.

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