|
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.GetC hanges(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(deletedChildRecor dsPostePlans)
End If
Me.PostesTableAdapter.Update(DsPlansEtCheminsPoste s.Postes)
If newChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(newChildRecords)
End If
If modifiedChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(modifiedChildReco rds)
End If
If modifiedChildRecordsReservoirs IsNot Nothing Then
Me.ReservoirsPostesTableAdapter.Update(modifiedChi ldRecordsReservoirs)
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 | |
Share:
|
Bob,
It is so much code, that I cannot really see everything in this message
however the update sequence is in my idea.
Delete Child records
Do parent updates
Do Child added and modified updates.
I thought that is not the sequence you are using.
If you have "on delete cascade" in your database for these than you can even
forgot the first step.
Cor
"Bob" <bd*****@sgiims.com> schreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl... 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.GetC hanges(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(deletedChildRecor dsPostePlans)
End If
Me.PostesTableAdapter.Update(DsPlansEtCheminsPoste s.Postes)
If newChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(newChildRecords)
End If
If modifiedChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(modifiedChildReco rds)
End If
If modifiedChildRecordsReservoirs IsNot Nothing Then
Me.ReservoirsPostesTableAdapter.Update(modifiedChi ldRecordsReservoirs)
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 | | |
Thanks
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Ob**************@TK2MSFTNGP05.phx.gbl... Bob,
It is so much code, that I cannot really see everything in this message however the update sequence is in my idea.
Delete Child records Do parent updates Do Child added and modified updates.
I thought that is not the sequence you are using.
If you have "on delete cascade" in your database for these than you can even forgot the first step.
Cor "Bob" <bd*****@sgiims.com> schreef in bericht news:%2****************@TK2MSFTNGP04.phx.gbl... 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.GetC hanges(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(deletedChildRecor dsPostePlans)
End If
Me.PostesTableAdapter.Update(DsPlansEtCheminsPoste s.Postes)
If newChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(newChildRecords)
End If
If modifiedChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(modifiedChildReco rds)
End If
If modifiedChildRecordsReservoirs IsNot Nothing Then
Me.ReservoirsPostesTableAdapter.Update(modifiedChi ldRecordsReservoirs)
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
| | |
Just looked at my code again. Thats exactly the sequnce that I'm using, so
why the concurrency problem?
Regards,
Bob
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Ob**************@TK2MSFTNGP05.phx.gbl... Bob,
It is so much code, that I cannot really see everything in this message however the update sequence is in my idea.
Delete Child records Do parent updates Do Child added and modified updates.
I thought that is not the sequence you are using.
If you have "on delete cascade" in your database for these than you can even forgot the first step.
Cor "Bob" <bd*****@sgiims.com> schreef in bericht news:%2****************@TK2MSFTNGP04.phx.gbl... 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.GetC hanges(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(deletedChildRecor dsPostePlans)
End If
Me.PostesTableAdapter.Update(DsPlansEtCheminsPoste s.Postes)
If newChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(newChildRecords)
End If
If modifiedChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(modifiedChildReco rds)
End If
If modifiedChildRecordsReservoirs IsNot Nothing Then
Me.ReservoirsPostesTableAdapter.Update(modifiedChi ldRecordsReservoirs)
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
| | |
Bob,
And you are sure that the rowstate of the deleted child records that should
go with the deleted parents is set (Or your database has on delete cascade
on the key of that?)
Cor
..
"Bob" <bd*****@sgiims.com> schreef in bericht
news:Op**************@TK2MSFTNGP05.phx.gbl... Just looked at my code again. Thats exactly the sequnce that I'm using, so why the concurrency problem? Regards, Bob "Cor Ligthert [MVP]" <no************@planet.nl> wrote in message news:Ob**************@TK2MSFTNGP05.phx.gbl... Bob,
It is so much code, that I cannot really see everything in this message however the update sequence is in my idea.
Delete Child records Do parent updates Do Child added and modified updates.
I thought that is not the sequence you are using.
If you have "on delete cascade" in your database for these than you can even forgot the first step.
Cor "Bob" <bd*****@sgiims.com> schreef in bericht news:%2****************@TK2MSFTNGP04.phx.gbl... 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.GetC hanges(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(deletedChildRecor dsPostePlans)
End If
Me.PostesTableAdapter.Update(DsPlansEtCheminsPoste s.Postes)
If newChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(newChildRecords)
End If
If modifiedChildRecords IsNot Nothing Then
Me.PostePlansTableAdapter.Update(modifiedChildReco rds)
End If
If modifiedChildRecordsReservoirs IsNot Nothing Then
Me.ReservoirsPostesTableAdapter.Update(modifiedChi ldRecordsReservoirs)
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
| | This discussion thread is closed Replies have been disabled for this discussion. Similar topics
16 posts
views
Thread by aurora |
last post: by
|
2 posts
views
Thread by Robin Tucker |
last post: by
|
3 posts
views
Thread by Karl |
last post: by
|
2 posts
views
Thread by John |
last post: by
|
7 posts
views
Thread by William E Voorhees |
last post: by
|
3 posts
views
Thread by John |
last post: by
|
1 post
views
Thread by =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= |
last post: by
|
5 posts
views
Thread by John |
last post: by
|
1 post
views
Thread by Henri.Chinasque |
last post: by
| | | | | | | | | | |