Using transactionScope with crm 2011 Sdk RRS feed

  • Question

  • Hello everybody,

    I'm using the transactionScope component to revert crm operations done via Sdk. When an exception occurs, changes are not reverted. Is not Crm 2011 compatible with transactionScope?

    Thank you!!

    Monday, January 2, 2012 3:50 PM

All replies

  • Hi,

    In CRM 2011 you can register your plugin in transaction refer http://msdn.microsoft.com/en-us/library/gg327941.aspx

    if there will be any exception in plugin,all the actions done during transaction will be rollback.

    Hope it will help

    Mahain : Check My Blog
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.
    Monday, January 2, 2012 5:56 PM
  • CRM 2011 does not support external control of transactions - i.e. it does not have calls that would do the equivalent of a commit/complete, or a rollback. Thus, it is not compatible with the TransactionScope class.

    You can use transactional behaviour in 2 ways in CRM 2011:

    • If you submit on request that will involve several data operations (e.g. by using the RelatedEntities property), then all of these operations will be applied as one atomic transaction
    • In a plugin, registered on a stage (20 or 40) within the transaction. If you use the IOrganizationService instance that is obtained from the IExecutionContext parameter, then any data operations will be in the scope of the original transaction

    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Tuesday, January 3, 2012 9:29 AM
  • Thank you...

    The operations we do are external to Crm and are in combination with others affecting other database, and the full set must be atomic.

    So we will have to make the reverting in Crm "by hand".

    Thank you again...

    Tuesday, January 3, 2012 9:47 AM
  • Hi Vermin2,

    As David say, you can only control the CRM transaction commit/rollback behavior by using the plugin pipeline transaction. If you throw an exception within your plugin and it is executing at stages 20 or 40, the current pipeline transaction will be rolled back, along with all operations that have been made using the pipeline OrganizationService. 

    If you want to execute commands against another database from within the pipeline transaction, provided that the database is on the same database server as CRM or accessible via a linked server, you can use:


    Be aware that this is not really supported and in future versions of the product, you may need to change the way that you gain access to the pipeline database transaction. This method will not work for Dynamics CRM Online.


    Tuesday, January 3, 2012 10:22 AM