locked
Plugin Error while executing sqlCommand.ExecuteNonQuery method RRS feed

  • Question

  • I have one AccountPostUpdate method plugin in which I execute store procedure on Same CRM SQL server. I pass connection string from secure section and I have same code executes from AccountPostCreate plugin just fine.

    As soon as the plugin try to execute sqlCommand.ExecuteNonQuery method, it throw below error. It timeouts. I can execute that store procedure from sql server itself and from other plugin. Only from this plugin it timeouts. I have plugin in below mode.

    IsolationMode="None"

    "

    Any idea what could be wrong??

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: An error occurred in the Plug-in PostCustomerUpdate.Detail:

    <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">

      <ErrorCode>-2147220891</ErrorCode>

      <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">

        <KeyValuePairOfstringanyType>

          <d2p1:key>OperationStatus</d2p1:key>

          <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value>

        </KeyValuePairOfstringanyType>

        <KeyValuePairOfstringanyType>

          <d2p1:key>SubErrorCode</d2p1:key>

          <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value>

        </KeyValuePairOfstringanyType>

      </ErrorDetails>

      <Message>An error occurred in the Plug-in PostCustomerUpdate.</Message>

      <Timestamp>2014-08-27T18:48:08.4435199Z</Timestamp>

      <InnerFault i:nil="true" />

      <TraceText>

    [TESTPlugin.Plugins: TESTPlugin.Plugins.PostCustomerUpdate]

    [c89b2d16-220d-e411-940c-0050568b5161: PostCustomerUpdate]

    Entered TESTPlugin.Plugins.PostCustomerUpdate.Execute(), Correlation Id: dd2244fd-9f51-48c5-b0f8-d66fe6b685b0, Initiating User: d0d135c6-0314-e411-940f-0050568b5161

    TESTPlugin.Plugins.PostCustomerUpdate is firing for Entity: account, Message: Update, Correlation Id: dd2244fd-9f51-48c5-b0f8-d66fe6b685b0, Initiating User: d0d135c6-0314-e411-940f-0050568b5161

    Exception: An error occurred in the ExecutePreCustomerCreate Plug-in.Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.    at TESTPlugin.Plugins.PostCustomerUpdate.CheckCustomerNumber(Entity entity, Guid userId, String strConnectionString)

       at TESTPlugin.Plugins.PostCustomerUpdate.ExecutePostCustomerUpdate(LocalPluginContext localContext)

    Exiting TESTPlugin.Plugins.PostCustomerUpdate.Execute(), Correlation Id: dd2244fd-9f51-48c5-b0f8-d66fe6b685b0, Initiating User: d0d135c6-0314-e411-940f-0050568b5161

    </TraceText>

    </OrganizationServiceFault>


    Wednesday, August 27, 2014 8:07 PM

Answers

  • Could you please explain what you're trying to do with your stored proc?

    If it wants to change the same Account record or any other directly associated records, you might end up in a deadlock scenario. I also suspect your PostCustomerUpdate plugins sycnhronously, which participates in a SQL transaction. Nevertheless, direct SQL changes to CRM database (bypassing the SDK) are neither supported nor recommended.

    The recommended approach is to expose this sort of 'external' stuff via a web service and have your plugins to call this web service.

    Anyway, try running the same plugging in asynchronous mode.

    • Marked as answer by Nicksoft2011 Monday, September 29, 2014 12:47 PM
    Wednesday, August 27, 2014 11:20 PM
  • Nihan,

          thanks for this update. but i am not trying to update any hting whithin CRM. that store procedure check few other stuff from our ERP System database and give out put back to plugin. Any idea?

             it is strange that same code works for other plugin.

     

    Thanks,

    Nick

    • Marked as answer by Nicksoft2011 Monday, September 29, 2014 12:48 PM
    Thursday, August 28, 2014 12:46 PM
  • Well, it's difficult to tell exactly without taking a detailed look at the code. Maybe your plugin and stored procedure are getting entangled in an Enterprise Transaction. Or it might be a simple timeout or something not-so-obvious different from your PostCreate plugin.

    As I suggested earlier, try running the plugin asynchronously, or move your logic to a workflow. If you still need a synchronous response, use a web service to expose ERP stuff to CRM, and call this web service from your plugin.

    You can also run a trace on database (e.g. SQL Profiler) to see what's going on at the back end.

    • Marked as answer by Nicksoft2011 Monday, September 29, 2014 12:48 PM
    Thursday, August 28, 2014 2:12 PM
  • Hi,

     In your error detail , it seems to be , in your stored procedure you want select the account that plugin executes.Plugin locks the record and you can not select the record from storedprocedure , wcf, 3rd dll , vs..If so in your stored produce , you must tell db , you want to read permission for that account.


    Polat Aydın Crm Software Developer

    • Marked as answer by Nicksoft2011 Monday, September 29, 2014 12:48 PM
    Thursday, August 28, 2014 2:25 PM

All replies

  • Could you please explain what you're trying to do with your stored proc?

    If it wants to change the same Account record or any other directly associated records, you might end up in a deadlock scenario. I also suspect your PostCustomerUpdate plugins sycnhronously, which participates in a SQL transaction. Nevertheless, direct SQL changes to CRM database (bypassing the SDK) are neither supported nor recommended.

    The recommended approach is to expose this sort of 'external' stuff via a web service and have your plugins to call this web service.

    Anyway, try running the same plugging in asynchronous mode.

    • Marked as answer by Nicksoft2011 Monday, September 29, 2014 12:47 PM
    Wednesday, August 27, 2014 11:20 PM
  • Nihan,

          thanks for this update. but i am not trying to update any hting whithin CRM. that store procedure check few other stuff from our ERP System database and give out put back to plugin. Any idea?

             it is strange that same code works for other plugin.

     

    Thanks,

    Nick

    • Marked as answer by Nicksoft2011 Monday, September 29, 2014 12:48 PM
    Thursday, August 28, 2014 12:46 PM
  • Well, it's difficult to tell exactly without taking a detailed look at the code. Maybe your plugin and stored procedure are getting entangled in an Enterprise Transaction. Or it might be a simple timeout or something not-so-obvious different from your PostCreate plugin.

    As I suggested earlier, try running the plugin asynchronously, or move your logic to a workflow. If you still need a synchronous response, use a web service to expose ERP stuff to CRM, and call this web service from your plugin.

    You can also run a trace on database (e.g. SQL Profiler) to see what's going on at the back end.

    • Marked as answer by Nicksoft2011 Monday, September 29, 2014 12:48 PM
    Thursday, August 28, 2014 2:12 PM
  • Hi,

     In your error detail , it seems to be , in your stored procedure you want select the account that plugin executes.Plugin locks the record and you can not select the record from storedprocedure , wcf, 3rd dll , vs..If so in your stored produce , you must tell db , you want to read permission for that account.


    Polat Aydın Crm Software Developer

    • Marked as answer by Nicksoft2011 Monday, September 29, 2014 12:48 PM
    Thursday, August 28, 2014 2:25 PM