I am wondering how resource expensive it is to perform a begin transaction on a connection and immediately update/insert a row into a database and leave this transaction hanging for several hours.
Basically I just want to perform a "series number" reservation for my document management system. My series are something that are very custom and I want that whenever a user presses the "Add new document" button, the next value will be allocated into my series allocation table. To allocate it I would insert a row into the allocation table. Next time, when a new user asks for the next value, it will read using NOLOCK hint so that they will see my pending inserted value so that they will know the next value also. If the user cancels the form that adds a new document, I would simply perform a rollback over my opened connection. If the connection is lost and I am in "add" mode, then I would check if current transaction id on which I allocated my series matches the current one. If not, then I would allocate another one. There is not a problem that a user loses a series due to connection lost.
What do you think? I feel like it's a very bad practice because it is in contradiction with the idea that I learned in my several years of software development: Open connection as late as possible and close it as soon as possible.
Thank you in advance!