In my web application a Session is created in the BeginRequest handler. All database operations are performed against this session. In the EndRequest handler, the session is used to create a transaction which is then committed. Afterward, the session is disposed. This wraps all database operations performed against the session into a single transaction.
When is it beneficial to create a transaction to be committed within the request-transaction? How is this done?
In other words, for what reason would I create a transaction for any purpose other than to commit all the database operations performed in the current request?
When a user visits a page, you want to log various things to the database – a Page Hit etc. This can happily occur on the same session but you want the page tracking to be flushed to the database, even if an error subsequently occurs.
For performance too, you will want to hold your transactions open for as short a time as possible. During your request you may be performing a lot of non-databased oriented operations during which time there is no reason to hold a transaction open.
Lots of other examples…