I have code that opens and closes the connection to the database via table adapters every time I update because it was throwing concurrency and other database exceptions left and right. Now, if I try to navigate through the records it throws concurrency exceptions? I can add, edit, delete records just fine now but just navigating is a problem.
To give an idea what I have done to correct concurrency errors I have pasted a bit of code below.
Cocurrancy control is a major issue in Database programming. Are you in a multuser environment?. If not your own adding and deleting is throwing this excepition.
You have to declare your cursor to be optimistic so that it take care of a dynamic update.
How would I declare the cursor to be optimistic? I have basically taught myself a lot of the stuff I have done, using forums and such, but I can't seem to find anything on making the cursor optimistic. Any ideas?
adLockReadonly -------- for read only you cannot update the rows
adLockPessimistic........ This lock is the most strict form of concurrency. The row is locked. Other users can read but can't edit. The lock is to be explictly released by the application.
adLockOptimistic......... This is the most common way of locking. The database automatically place a lock when it updates the concerned row. It assumes that two users very seldom update a row instantly.
adLockBatchOptimistic... When a bunch of records are down loaded for a particular user, the server disconect the user. The user in his own time update it and establish a new connection to the database to make it committed.
See, I have used the common word as cursor. It need not be actually a cursor. Any table in any database is associated with theses properties, Otherwise, it will be chaos Veena, when you try to access it and modify.
Along with the particular table adapter connection open
Me.TableAdapter.Connection.Open()
you have to set what type of adapter you are going to use on the table.
PrivateSub CRS_AccomplishBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CRS_AccomplishBindingNavigatorSaveItem.Click
Try
If(Not(ConnectionState.Executing))Then
Me.CRS_AccomplishTableAdapter.Connection.Open()
Me.CRS_AccomplishTableAdapter.Update
Me.PortfolioDBDataSet.CRS_Accomplish)
MsgBox("Update Successful")
Else
MsgBox("The Connection is currently in use, please wait a
moment and try again")
EndIf
Catch dbcx As Data.DBConcurrencyException
Dim response As Windows.Forms.DialogResult
response = MsgBox("Concurrency Exception",
MessageBoxButtons.OK)
Catch ex As Exception
MsgBox("An error was thrown while trying to update the
database")
Finally
Me.CRS_AccomplishTableAdapter.Connection.Close()
End Try
EndSub
Now, I added the open stuff and it seems to only throw an exception when I rapidly add and then delete a lot of records. I don't think that should be a major problem, but I don't know if it is the rapidly or the a lot part that is screwing it up.
Last edited by Mr.Wobbles; Jun 21st, 2007 at 12:53 pm.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.