locked
How to manage transactions in CRM 4.0 using CRM SDK RRS feed

  • Question

  • hi experts...

    I am new in CRM development and seeking a help as bellow...

    I am creating/updating my custom/built-in entities through visual studio using CRM SDK. In a single event I need to create a new entity and need to update an existing one.

    Giving a real example (step by step):

    1. Creating a custom Entity named [Distribution]
    2. Adding a file (Annotation) in the Distribution entity (actually creating a new annotation entity for the newly created distribution).

    But it may happen that an error occured while adding the file as an annotation with the Distribution entity just after creating the distribution entity successfully.

    What I need to do is in this case...just rollback the changes that created the Distribution entity.

    And if the file is added successfully then commit it.

    Is there any way to accomplish this task through CRM SDK...???

    Thanks in advance...
    Tuesday, August 18, 2009 5:12 AM

Answers

  • Hi Rehman, Unfornatelly MS  CRM Sdk doesn't support transactions as yet. Not in CRM 4.0 at least
    I think they may gave teh trasactions object in CRM 5 only in Plugin.

    So for you either you have to have to rollback explicitly in this case. what i means if the error in the plugin  comes while uploading annotation entity, you delete the regarding entity if the regarding enttiy = "Distribution"

    You can add this code to your post- annotation plugin

    public void execute()
    {

    try{
    }
    catch(Exception ex)
    {
              if ( entity.regarding  == "Distribution")
                  // then delete the regarding entity for rollback complete.
    }

    }
    Tuesday, August 18, 2009 5:38 AM

All replies

  • Hi Rehman, Unfornatelly MS  CRM Sdk doesn't support transactions as yet. Not in CRM 4.0 at least
    I think they may gave teh trasactions object in CRM 5 only in Plugin.

    So for you either you have to have to rollback explicitly in this case. what i means if the error in the plugin  comes while uploading annotation entity, you delete the regarding entity if the regarding enttiy = "Distribution"

    You can add this code to your post- annotation plugin

    public void execute()
    {

    try{
    }
    catch(Exception ex)
    {
              if ( entity.regarding  == "Distribution")
                  // then delete the regarding entity for rollback complete.
    }

    }
    Tuesday, August 18, 2009 5:38 AM
  • If so..., then there is a possibility to break the consistency of the data in CRM. And I think its really going to be annoying...

    Actually I am thinking about the network problem as it take a little longer to update/create an entity. Because network may go down between the updates..

    But thanks for your response...
    Tuesday, August 18, 2009 6:39 AM
  • Well there is an alternative way of using SqlTransaction and SqlConnection object to the MS CRM Database. However that offcourse is not supported plus you have to do lot more work to understand and then change anything in MS CRM database directly.
    Tuesday, August 18, 2009 7:08 AM
  • If it is not supported then how can I do that???

    Can you please let me know something about the alternative way?
    Tuesday, August 18, 2009 8:00 AM
  • Well quite honestly, i have never tried it myself. You have to dig deep In MS CRM database and find out how you can create custom entity (in  your case "Distribution") and then delete it as well. MS CRM database is not a very straight fwd database so you may have to check a quite a few tables to find out where the data is kept .
    Tuesday, August 18, 2009 8:07 AM
  • hi khan,

    thanks for your prompt response.

    Actually I have tried a couple of months ago to create/update entities directly connecting to CRM database. Got a very small knoledge on it's architechture.

    But it takes a long time just to understand the relations between the entities and to find the columns... and others...

    Still some other issues are there and I just gave up that way and working through SDK now.

    And now I dont want to go back to use the DB directly...

    Lets see what happens....

    Anyways... thanks again...
    • Proposed as answer by Mou19 Wednesday, September 30, 2009 7:41 PM
    Tuesday, August 18, 2009 8:17 AM