Monday, November 29, 2010

ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.

Hi..

Recently I came across one wierd Error found by one of my QA friend after we imported a new CRM 4.0 organization into our development environment. The error stated something like below (Error can be tracked in the trace log files. Check out this link to find out how to enable Tracing in CRM 4.0)

"System.InvalidOperationException: ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized."


We were facing this error on all the ISV aspx pages embedded into CRM and that too was user specific i.e. for some users these ISV pages worked fine but others were facing the above error.

After loads of digging and googling around the web, i came across this link which provided the solution but this was not the case for our error.

Solution : 
       The Solution was really very simple after we found it... The issue which we were facing was due to missing Default Organization for some of the users. We just updated the Default Organization for those users and the system go up and running.

Database: MSCRM_CONFIG
Table : Organization
Query : Select Id, UniqueName From Organization
              Get the Id from the above query result (In case of Multi-Tenancy, take the id of the organization which you want as default for the particular user)


Database: MSCRM_CONFIG
Table : SystemUser
Query : Update SystemUser
              Set DefaultOrganizaionId = <>
              Where Id = <>

Updating the DefaultOrganizationIds for the users will fix the above error and you are good to go to your boss and boast of your achievement !!! J

Hope you find this solution useful. Feel free to post the query in case you need help for Dynamics CRM and this post. J