Pregunta

¿Cuál es el momento adecuado para utilizar un SqlTransaction?

Las uso para todos de mi INSERT, UPDATE y DELETE.

Es este el uso correcto o estoy haciendo un poco excesivo?

¿Fue útil?

Solución

Use a transaction when you want a series of statements to be treated atomically - that is either they all succeed and are committed, or they are all rolled back.

Since simple statements are already atomic you don't need to explicitly create a transaction around each and every individual statement.

Otros consejos

You only need a transaction if you plan to do multiple statements, and plan to rollback all of the data changes that resulted from the statements if an error somewhere down the line occurs. Wrapping single update/delete statements is not needed. If an error occurs with a single command, simply catch and handle the error in your front-end code.

If your commands are only single issued, and not a group, then it is probably overkill. Transactions are used to group sql commands together, a group that must have all members succeed, or none at all.

http://en.wikipedia.org/wiki/Atomicity_%28database_systems%29

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top