B
Bob
While testing my my program I came up with a consistency exception. My
program consists of three datagridviews, One called dgvPostes which is the
parent grid and its two children,one called dgvPlans and the other dgvTanks.
What happens is as follows. I will either create or edit a record in the
datagridview dgvPlans and call the Updatedb procedure (code below). The
first save works OK. Then when that is done, on the same record I will try
to edit it and do another UpdateDB. That updatedDB execution will catch a
concurrency exception error. But there is no concurrent use of the database.
I am the only one who is using it and updating the records. The code
structure that I used below is straight out of the Microsoft sample on their
web site. I went back to the dataset designer and changed the properties to
exclude (uncheck) the optimistic concurrency checking when creating the
datatable definitions. Then I tried my code again and I no longer got the
Concurrency exception. From what I see, if you do NOT check the optimistic
concurrency checking there is NO concurrency checking at all. On the other
hand if you do check it, it doesn't seem to work right since the changes
that it caught as concurrency violations were in fact ok.
This is the code snippet of my updatedb method. Can someone please tell me
if I should do something to it to avoid the concurrency exception on the
second edit-save. It occurs on the line
DsPlansEtCheminsPostes.AcceptChanges()
Private Sub UpdateDB()
Me.Validate()
Me.FKReservoirsPostesPostesBindingSource.EndEdit()
Me.FKPostePlansPostesBindingSource.EndEdit()
Me.PostesBindingSource.EndEdit()
'We can only update the database's PostesPlans table and the field that is
bound to the cheminPoste
'in table poste.
'if we had deleted any records in posteplans, find them
Dim deletedChildRecordsPostePlans As
dsPlansEtCheminsPostes.PostePlansDataTable = _
CType(DsPlansEtCheminsPostes.PostePlans.GetChanges(Data.DataRowState.Deleted),
dsPlansEtCheminsPostes.PostePlansDataTable)
'We do not need to verify the reservoirsPostes part of this because we can
never change them
'If we had deleted any poste plans, find em
Dim newChildRecords As dsPlansEtCheminsPostes.PostePlansDataTable = _
CType(DsPlansEtCheminsPostes.PostePlans.GetChanges(Data.DataRowState.Added),
dsPlansEtCheminsPostes.PostePlansDataTable)
'If we had modified any child records, get them
Dim modifiedChildRecords As dsPlansEtCheminsPostes.PostePlansDataTable = _
CType(DsPlansEtCheminsPostes.PostePlans.GetChanges(Data.DataRowState.Modified),
dsPlansEtCheminsPostes.PostePlansDataTable)
Dim modifiedChildRecordsReservoirs As
dsPlansEtCheminsPostes.ReservoirsPostesDataTable = _
CType(DsPlansEtCheminsPostes.ReservoirsPostes.GetChanges(Data.DataRowState.Modified),
dsPlansEtCheminsPostes.ReservoirsPostesDataTable)
'Note we do not have any possibility of adding or deleting reservoirspostes
records in this application.
'So we don't have to check for new or deleted records, we will only check
for modified records.
Try
If deletedChildRecordsPostePlans IsNot Nothing Then
Me.PostePlansTableAdapter.Update(deletedChildRecordsPostePlans)
End If
Me.PostesTableAdapter.Update(DsPlansEtCheminsPostes.Postes)
If newChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(newChildRecords)
End If
If modifiedChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(modifiedChildRecords)
End If
If modifiedChildRecordsReservoirs IsNot Nothing Then
Me.ReservoirsPostesTableAdapter.Update(modifiedChildRecordsReservoirs)
End If
DsPlansEtCheminsPostes.AcceptChanges()
Me.Cursor = Cursors.Default
MsgBox(My.Resources.msgSaveOK)
Catch ex As Exception
Me.Cursor = Cursors.Default
EM.HandleException(ex, False, My.Resources.msgNoSave,
My.Resources.msgActionNotPerformed, My.Resources.msgTryAgain)
Finally
Me.Cursor = Cursors.Default
If deletedChildRecordsPostePlans IsNot Nothing Then
deletedChildRecordsPostePlans.Dispose()
End If
If newChildRecords IsNot Nothing Then
newChildRecords.Dispose()
End If
If modifiedChildRecords IsNot Nothing Then
modifiedChildRecords.Dispose()
End If
End Try
End Sub
Thanks for your help,
Bob
program consists of three datagridviews, One called dgvPostes which is the
parent grid and its two children,one called dgvPlans and the other dgvTanks.
What happens is as follows. I will either create or edit a record in the
datagridview dgvPlans and call the Updatedb procedure (code below). The
first save works OK. Then when that is done, on the same record I will try
to edit it and do another UpdateDB. That updatedDB execution will catch a
concurrency exception error. But there is no concurrent use of the database.
I am the only one who is using it and updating the records. The code
structure that I used below is straight out of the Microsoft sample on their
web site. I went back to the dataset designer and changed the properties to
exclude (uncheck) the optimistic concurrency checking when creating the
datatable definitions. Then I tried my code again and I no longer got the
Concurrency exception. From what I see, if you do NOT check the optimistic
concurrency checking there is NO concurrency checking at all. On the other
hand if you do check it, it doesn't seem to work right since the changes
that it caught as concurrency violations were in fact ok.
This is the code snippet of my updatedb method. Can someone please tell me
if I should do something to it to avoid the concurrency exception on the
second edit-save. It occurs on the line
DsPlansEtCheminsPostes.AcceptChanges()
Private Sub UpdateDB()
Me.Validate()
Me.FKReservoirsPostesPostesBindingSource.EndEdit()
Me.FKPostePlansPostesBindingSource.EndEdit()
Me.PostesBindingSource.EndEdit()
'We can only update the database's PostesPlans table and the field that is
bound to the cheminPoste
'in table poste.
'if we had deleted any records in posteplans, find them
Dim deletedChildRecordsPostePlans As
dsPlansEtCheminsPostes.PostePlansDataTable = _
CType(DsPlansEtCheminsPostes.PostePlans.GetChanges(Data.DataRowState.Deleted),
dsPlansEtCheminsPostes.PostePlansDataTable)
'We do not need to verify the reservoirsPostes part of this because we can
never change them
'If we had deleted any poste plans, find em
Dim newChildRecords As dsPlansEtCheminsPostes.PostePlansDataTable = _
CType(DsPlansEtCheminsPostes.PostePlans.GetChanges(Data.DataRowState.Added),
dsPlansEtCheminsPostes.PostePlansDataTable)
'If we had modified any child records, get them
Dim modifiedChildRecords As dsPlansEtCheminsPostes.PostePlansDataTable = _
CType(DsPlansEtCheminsPostes.PostePlans.GetChanges(Data.DataRowState.Modified),
dsPlansEtCheminsPostes.PostePlansDataTable)
Dim modifiedChildRecordsReservoirs As
dsPlansEtCheminsPostes.ReservoirsPostesDataTable = _
CType(DsPlansEtCheminsPostes.ReservoirsPostes.GetChanges(Data.DataRowState.Modified),
dsPlansEtCheminsPostes.ReservoirsPostesDataTable)
'Note we do not have any possibility of adding or deleting reservoirspostes
records in this application.
'So we don't have to check for new or deleted records, we will only check
for modified records.
Try
If deletedChildRecordsPostePlans IsNot Nothing Then
Me.PostePlansTableAdapter.Update(deletedChildRecordsPostePlans)
End If
Me.PostesTableAdapter.Update(DsPlansEtCheminsPostes.Postes)
If newChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(newChildRecords)
End If
If modifiedChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(modifiedChildRecords)
End If
If modifiedChildRecordsReservoirs IsNot Nothing Then
Me.ReservoirsPostesTableAdapter.Update(modifiedChildRecordsReservoirs)
End If
DsPlansEtCheminsPostes.AcceptChanges()
Me.Cursor = Cursors.Default
MsgBox(My.Resources.msgSaveOK)
Catch ex As Exception
Me.Cursor = Cursors.Default
EM.HandleException(ex, False, My.Resources.msgNoSave,
My.Resources.msgActionNotPerformed, My.Resources.msgTryAgain)
Finally
Me.Cursor = Cursors.Default
If deletedChildRecordsPostePlans IsNot Nothing Then
deletedChildRecordsPostePlans.Dispose()
End If
If newChildRecords IsNot Nothing Then
newChildRecords.Dispose()
End If
If modifiedChildRecords IsNot Nothing Then
modifiedChildRecords.Dispose()
End If
End Try
End Sub
Thanks for your help,
Bob