Note that there are some explanatory texts on larger screens.

plurals
  1. POCould not save; currently locked by another user. OledbException was unhandled
    primarykey
    data
    text
    <p>I have a background worker thats doing some database work for me. The reason why I resorted to using using the background worker is because the database work is taking up a lot of time. So the code works the first time but as you continue to update the database then then you get "Could not save; currently locked by another user. OledbException was unhandled". Is the a way to go around this issue. This is my code</p> <pre><code> Private Sub DoSaveUsersAuditForUpdate_Click() Dim myConn As OleDbConnection = frmLogIn.Conn SyncLock myConn 'Insert Previous data before the Update 'myConn = frmLogIn.Conn Dim cmdInsert As OleDbCommand = New OleDbCommand("Insert INTO UsersAudit (Reference,Comment) VALUES (?,?)", myConn) cmdInsert.Parameters.Add("@Reference", OleDbType.WChar).Value = txtReference.Text cmdInsert.Parameters.Add("@Comment", OleDbType.WChar).Value = "Update Existing Users Details" myConn.Open() cmdInsert.ExecuteNonQuery() myConn.Close() End SyncLock Dim myKonn As OleDbConnection = frmLogIn.Conn SyncLock myKonn 'Insert Current data after the Update 'myKonn = frmLogIn.Conn Dim cmdInsertOriginal As OleDbCommand = New OleDbCommand("Insert INTO UsersAudit (Reference,Comment) VALUES (?,?)", myKonn) cmdInsertOriginal.Parameters.Add("@Reference", OleDbType.WChar).Value = txtReference.Text cmdInsertOriginal.Parameters.Add("@Comment", OleDbType.WChar).Value = "New User" myKonn.Open() cmdInsertOriginal.ExecuteNonQuery() myKonn.Close() End SyncLock End Sub </code></pre> <p>Here's How I am calling it</p> <pre><code> Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork DoSaveUsersAuditForUpdate_Click() End Sub </code></pre> <p>this where it all comes together</p> <pre><code> Private Sub btnUpdate_Click(sender As System.Object, e As System.EventArgs)Handles btnUpdate.Click </code></pre> <p>BackgroundWorker1.RunWorkerAsync() 'Dim workerThread As New Thread(AddressOf DoSaveUsersAuditForUpdate_Click) 'workerThread.Start() DoUpdateUsers_Click(sender, e) UsersGridViewGridFormating() End Sub</p> <pre><code> Private Sub UsersGridViewGridFormating() Dim myConn As OleDbConnection = frmLogIn.Conn SyncLock myConn Dim iSql As String = "SELECT * FROM Users WHERE UserDeleted =@UserDeleted" Dim da As New OleDbDataAdapter(iSql, myConn) da.SelectCommand.Parameters.AddWithValue("@UserDeleted", False) dTable.Clear() da.Fill(dTable) myConn.Close() Dim dv As DataView = New DataView(dTable) dv.Sort = "UserName asc" dTable = dv.ToTable UsersMasterGridview.DataSource = dTable UsersMasterGridview.Visible = True UsersMasterGridview.Focus() lblNumberofRecords.Text = dTable.Rows.Count &amp; " Records" End SyncLock End Sub </code></pre> <p>Any Help this all the code I am using </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload