D
Dmitry Sazonov
I have parent-child 2 datatables with database trigger set on "delete
cascade". When I delete row from parent table, trigger deletes all related
child rows.
Here is a problem: After I deleted parent record and I'm calling
DataAdapter.Update() on child table I'm getting an error:
"Concurrency violation: the DeleteCommand affected 0 records."
Because it already deleted by trigger.
So, I tried many methods to solve it:
- I tried to prevent DataAdapter from calling delete operation. I set
property "DeleteCommand" of my DataAdapter to "null" and got exeption
"Update requires a valid DeleteCommand when passed DataRow collection with
deleted rows."
- I tried to set DataAdapter property ContinueUpdateOnError = true; but it
did not really helped and I do not want to block all error information ...
- I tried to call AcceptChanges() for each child row. This is a way to
go! But "DeletedRowInaccessibleException" occurred "Deleted row information
cannot be accessed through the row".
- I was not been able to use version information because I do not need to
access specific column - I need to call method on whole row...
- I tried to set On RowDeleted event and got same exeption.
- I tried to make a copy of all child rows before deletion parent row. It
did not allow me to delete parent row...
- I tried to enumerate all child rows ("foreach"), and call AcceptChanges()
for each Deleted row. After first accepted row, an exeption raised
"Collection was modified; enumeration operation may not execute."
- Also I called DataSet.GetChanges(), enumerate it and call
AcceptChanges()... but got "Collection was modified..." exeption.
- I tried to remove Relatoin before delete operation...
- I tried to set Delete rule in this particular relaton to "None" instead
default. It did not help.
+ Only one way to fix it is remove trigger and disable referential
integrity. I do not like this way...
I sure I'm missing something really small here. But nothing helps. May be
somebody already had this "trigger" related problem ?
Thank you in advance.
cascade". When I delete row from parent table, trigger deletes all related
child rows.
Here is a problem: After I deleted parent record and I'm calling
DataAdapter.Update() on child table I'm getting an error:
"Concurrency violation: the DeleteCommand affected 0 records."
Because it already deleted by trigger.
So, I tried many methods to solve it:
- I tried to prevent DataAdapter from calling delete operation. I set
property "DeleteCommand" of my DataAdapter to "null" and got exeption
"Update requires a valid DeleteCommand when passed DataRow collection with
deleted rows."
- I tried to set DataAdapter property ContinueUpdateOnError = true; but it
did not really helped and I do not want to block all error information ...
- I tried to call AcceptChanges() for each child row. This is a way to
go! But "DeletedRowInaccessibleException" occurred "Deleted row information
cannot be accessed through the row".
- I was not been able to use version information because I do not need to
access specific column - I need to call method on whole row...
- I tried to set On RowDeleted event and got same exeption.
- I tried to make a copy of all child rows before deletion parent row. It
did not allow me to delete parent row...
- I tried to enumerate all child rows ("foreach"), and call AcceptChanges()
for each Deleted row. After first accepted row, an exeption raised
"Collection was modified; enumeration operation may not execute."
- Also I called DataSet.GetChanges(), enumerate it and call
AcceptChanges()... but got "Collection was modified..." exeption.
- I tried to remove Relatoin before delete operation...
- I tried to set Delete rule in this particular relaton to "None" instead
default. It did not help.
+ Only one way to fix it is remove trigger and disable referential
integrity. I do not like this way...
I sure I'm missing something really small here. But nothing helps. May be
somebody already had this "trigger" related problem ?
Thank you in advance.