Run selective code in transaction
Hi,
I am very new to this enterprise services based programming (COM+).
I have created a Enterpriseservices based component with the TransactionOption property set to 'Supported'.
Now, I would like to know the following things.
- How to handle database related queries which dont require any type of locking?
- How to run a part of a subroutine in a transaction?
- While in transaction, whatever tables I have queried gets locked until I commit or abort the transaction. Because of this I am facing deadlock problems. How to handle such situations where I am sure that a lock to particular table is required eventhough its under a transaction?
Thanx in advance.
Regards,
Ram.
Hey Ram,
In regards to your first question, I'm not quite sure I understand what you are asking.
For your second question, if you are using at least the .net framework 2.0 you should take a look at TransactionScope class. You can pass a TransactionScopeOptions value of Suppress which will suppress the Ambient Transaction for the duration of the scope. This would essentially allow you to embed a section of non-transacted code in your ServicedComponent call. Note, since you are already in a COM+ Transacted context you don't necessarily need to specify an EnterpriseServicesInteropOption of Full or Automatic since Automatic is the default. Automatic will ensure that since you are already in a COM+ Transacted context that the two will be in sync and the COM+ Transaction will indeed be supressed for the duration of the scope. Can I ask why it is you are using EnterpriseServices instead of System.Transactions directly? Are there other services besides Transactions that you require?
Third question, what type of deadlock are you seeing? If you do end up with contention in the database due to two seperate Transactions, one of the Transactions should time out and abort allowing the second to make forward progress.
Miguel