In CRM sometimes we have a requirement to create/update multiple records using custom workflow. In my case I designed a custom workflow which will create multiple tasks depending upon some condition. When single record is created through workflow it just worked fine but for multiple records i got two errors
1. “Invalid Pointer”
2.Encountered disposed CrmDbConnection when it should not be disposed You cannot create a SqlExecutionContext from another
The main reason of this error is, when the workflow runs against multiple records it uses the same class level varibales. If the IOrganizationService variable is declared in class level then after declaration of the variable in first instance, the second instance also use the same variable for which it gives the above errors.
The solution for this scenario is that declare the service variable as function-level variable not as a class level so that one instance of execution can’t use other instance variable.