transaction and open table

  • Thread starter Thread starter Ryan Liu
  • Start date Start date
R

Ryan Liu

Hi,

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?

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?

Thanks a lot!
R L
 
Ryan Liu said:
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.
 
Ryan Liu said:
Hi,

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?

The only time you need to be in a transactional mode is when you are
updating, inserting or deleting records using a database table.
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?

Yes, once the access is completed, then the connection should be closed and
disposed, each time after the access.

http://www.sql-server-performance.com/jk_ado_transactions.asp

You should use Google and look up the ADO.NET *Using* statement that
opens/closes/disposes things for you automatically.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top