"Ryan Liu" <Ry********@yahoo.comwrote in message
news:el**************@TK2MSFTNGP04.phx.gbl...
I have few db write and read to execute, so I use transaction.
Is that a problem or is that a regular way that I only use transaction on
some cmds only, and other cmds I do not use trasaction, esp those read
actions, or even use another dbconnection to read?
It depends on what you are trying to accomplish. If the transaction is
properly isolated (which you control through the transaction isolation
level), then those commands that you execute outside of the transaction will
not see the changes that you have done inside the transaction until the
transaction is committed. This may or may not be what you want to happen.
Moreover, since the transaction will place locks on the database to
accomplish the isolation, depending on what you are doing you risk that the
database commands that you are executing outside of the transaction might
get blocked waiting for the transaction to finish. You certainly don't want
this to happen, because the blocked command would stop your program from
proceeding to complete the transaction, and therefore would never get
unblocked.
BTW, what does "open table" menas? Is that table only be "open" when
someone
read or write it. Once all user finish read or write the db table, the
table should be "closed", is that right?
If you are sending Sql commands to a database, then the tables are not
'open' or 'closed'. They simply get some locks placed upon them when they
are accessed inside a transaction, and the locks are removed when the
transaction completes. This is automatic, and you don't have to do anything
special for it to happen.