J
J055
Hi
I've been puzzling over this one for a while now. I'm not really sure what
the best and cleanest approach would be here. This is what I want to do.
A User enters some values in a FormView control and submits the form.
A CustomValidator checks the database for duplicate entries. If a duplicate
is found the Page.IsValid property is made false and the user gets the error
message. If the Validation passes the ObjectDataSource control calls the
Insert method (or Update) of the BLL class and does the DB operation.
Standard stuff then.
The problem with the above is that it is not contained within a DB
transaction. If another user entry with the same values occurs in between
the first Validation and Insert functions then an SqlException will be
thrown with a unique constraint error.
I've thought of not using the Validation control and instead relying on a
custom exception based on the SqlException and checking for it in the
ObjectDataSource Inserted and Updated events. I don't like this because it
relies on the database having the correct constraints setup and when the
Inserted event fires the FormView control clears the input controls values.
So my questions are - can I make the CustomValidator and Insert/Update code
participate in the same DB transaction? I can't see how. Or is there another
way of achieving these requirements using sound practises together with the
standard server controls?
Many thanks
Andrew
I've been puzzling over this one for a while now. I'm not really sure what
the best and cleanest approach would be here. This is what I want to do.
A User enters some values in a FormView control and submits the form.
A CustomValidator checks the database for duplicate entries. If a duplicate
is found the Page.IsValid property is made false and the user gets the error
message. If the Validation passes the ObjectDataSource control calls the
Insert method (or Update) of the BLL class and does the DB operation.
Standard stuff then.
The problem with the above is that it is not contained within a DB
transaction. If another user entry with the same values occurs in between
the first Validation and Insert functions then an SqlException will be
thrown with a unique constraint error.
I've thought of not using the Validation control and instead relying on a
custom exception based on the SqlException and checking for it in the
ObjectDataSource Inserted and Updated events. I don't like this because it
relies on the database having the correct constraints setup and when the
Inserted event fires the FormView control clears the input controls values.
So my questions are - can I make the CustomValidator and Insert/Update code
participate in the same DB transaction? I can't see how. Or is there another
way of achieving these requirements using sound practises together with the
standard server controls?
Many thanks
Andrew