Whether database data writing and non-database operations need to be controlled by transactions, or other better methods

specific scenario: you need to write a piece of data to the database and upload an image at the same time. The name of the picture is the ID, to which the data is written. If the upload of the picture fails, do not write this data either.

solution: 1, if the picture fails to upload, delete the data (what if the deletion fails? I wrote it in the catch code of try {} catch {})
2, using database transaction processing, catch to error, and roll back

directly.

I think the second kind is a little safer. I don"t know how the gods usually deal with this problem.

Apr.08,2021

if all your business uses stored procedures, of course it is consistent

but be reasonable. If everything else is coded, you can still handle it according to normal code

.
Menu