并发冲突更新命令 [英] Concurrency violation the update command

查看:61
本文介绍了并发冲突更新命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



有人可以帮我。如何摆脱这个错误。 并发违规更新命令我在过去几天一直在苦苦挣扎。从互联网上尝试了许多解决方案但无法解决此问题。可能是,我完全是菜鸟。



我尝试了什么:



Hi All,

Can some one please assist me. How to get rid of this error. concurrency violation the update command I have been struggling from the last couple of days. Tried many solutions from the internet but unable to resolve this issue. May be, I am completely rookie.

What I have tried:

Imports Microsoft.Office
Imports System.Data.OleDb
Public Class Form1
    Dim dt As New DataTable
    Dim cnn As New OleDb.OleDbConnection


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


        'filling analyst filter

        Dim sText As String = String.Empty
               Dim sConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\ecxx-store\Exxx xxxxsk\Txx Axxx\Enxx Flxxx\Source\Exx_Exxx_Flagging.accdb" 'Put your connection string in here

        Using cn As New OleDb.OleDbConnection(sConnString)
            cn.Open()
            Dim cmd As New OleDb.OleDbCommand("SELECT Distinct Analyst FROM EF ORDER BY Analyst", cn)
            Dim r As OleDb.OleDbDataReader = cmd.ExecuteReader()

            While r.Read()
                ComboBox7.Items.Add(r("analyst"))


            End While
            r.Close()

            cn.Close()
        End Using

        'end of filling analyst filter

        Me.EFTableAdapter.Fill(Me.Exx_Exxxx_ShippingDataset.EF)



        Me.Label19.Text = "Welcome " & StrConv(Environment.MachineName, vbProperCase)
        Me.Label20.Text = EFBindingSource.Count.ToString() & " entries"

        'Setting Followup Status
        Me.ComboBox8.Text = "Waiting for approval"




        'disabling Second Analyst Details
        Me.txtsecondanalyst.Enabled = False
        Me.txtapproval.Enabled = False
        Me.txtnotes.Enabled = False

    End Sub

 Private Sub txtdof_ValueChanged(sender As Object, e As EventArgs) Handles txtdof.ValueChanged
        Me.txtnd.Text = DateDiff(DateInterval.Day, CDate(txtdof.Text), Now())
    End Sub

    Private Sub ComboBox7_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox7.SelectedIndexChanged
        If IsNothing(Me.ComboBox8.Text) Then
            EFBindingSource.Filter = "[Analyst] LIKE '%" & ComboBox7.Text & "%'"
        Else
            EFBindingSource.Filter = "[FollowupStatus] LIKE '%" & ComboBox8.Text & "%' AND [Analyst] Like '%" & ComboBox7.Text & "%'"

        End If

        'count of datagrid
        Me.Label20.Text = EFBindingSource.Count.ToString() & " entries"
    End Sub

    Private Sub ComboBox8_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox8.SelectedIndexChanged
        If IsNothing(Me.ComboBox7.Text) Then
            EFBindingSource.Filter = "[FollowupStatus] LIKE '%" & ComboBox8.Text & "%'"
        Else
            EFBindingSource.Filter = "[FollowupStatus] LIKE '%" & ComboBox8.Text & "%' AND [Analyst] Like '%" & ComboBox7.Text & "%'"

        End If

        'count of datagrid
        Me.Label20.Text = EFBindingSource.Count.ToString() & " entries"



    End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'update
        Me.txtnd.Visible = True

        Me.txtnd.Text = DateDiff(DateInterval.Day, CDate(txtdof.Text), Now())

        On Error GoTo SaveErr

        EFBindingSource.EndEdit()
        EFTableAdapter.Update(Exx_Exxxx_ShippingDataset.EF)


        Me.txtsecondanalyst.Enabled = False
        Me.txtapproval.Enabled = False
        Me.txtnotes.Enabled = False



        MsgBox("Record Updated or Saved")


SaveErr:

    End Sub

 Private Sub Form1_Closed(sender As Object, e As EventArgs) Handles Me.Closed
        EFBindingSource.EndEdit()
        Me.TableAdapterManager1.UpdateAll(Me.Exx_Exxx_ShippingDataset)
    End Sub
End Class

推荐答案

当出现并发错误时您尝试更新的数据已经在您获得更改的数据和尝试执行更新的时间之间进行了更新。



如果发生在UPDATE语句WHERE子句中。它正在查找不仅基于记录ID的记录,而是基于ID和所有与之前检索的值匹配的字段值。 UPDATE确实执行但受影响的记录数量返回为0而不是1.这就是并发错误出现的地方。



没有一个小修复问题。您必须调试代码和数据,以找出问题所在的位置以及首先出现问题的原因。只有这样才能弄明白真正的修复是什么。
A concurrency error occurs when the data you're trying to update has already been updated between the time you got the data you were changing and the time you're trying to execute your update.

If occurs in the UPDATE statement WHERE clause. It's looking for a record not based on the record ID alone but based on the ID and all of the field values matching the value that you retrieved before. The UPDATE does execute but the number of record affected came back as 0 instead of 1. That's where the concurrency error comes up.

There is no one little fix for this problem. You have to debug the code AND the data to find out where the problem is and why it is occurring in the first place. Only then can you figure out what the true "fix" is going to be.


这篇关于并发冲突更新命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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