MSCRM to call Store Proc on Plugin

Proposed Answer MSCRM to call Store Proc on Plugin

  • Saturday, November 17, 2012 8:07 AM
     
      Has Code

    I'mveryconfused,Icall a stored procedureon the Plug .It is timeout,

    but when  I debug the Plugin ,the stored procedure is able to run!!

              //con.Open();
                ////SqlTransaction st = con.BeginTransaction(IsolationLevel.ReadUncommitted);
                //SqlCommand command = new SqlCommand();
                //command.CommandType = CommandType.StoredProcedure;
                //command.Connection = con;
                ////command.Transaction = st;
                //command.CommandText = "[dbo].[usp_create_MSISDNPoolInitialization]";
                //command.CommandTimeout = 0;
                
                //CrmLogOperation.addCrmLog(command.CommandText);
                ////// 依次把参数传入存储过程
                //if (param != null)
                //{
                //    foreach (SqlParameter parameter in param)
                //        command.Parameters.Add(parameter);
                //}
                //CrmLogOperation.addCrmLog("command.ExecuteNonQuery();");
                
                //command.ExecuteNonQuery();
                ////st.Commit();
                //command.Dispose();
                //con.Close();
                //CrmLogOperation.addCrmLog("Completed");


    <form action="http://translate.google.cn/?hl=zh-CN&newwindow=1&q=guaranteed&um=1&ie=UTF-8&sa=N&tab=wT" closure_uid_ixitcd="74" enctype="application/x-www-form-urlencoded" id="gt-form" method="get" name="text_form" target=""> </form>
    <iframe allowtransparency="" class="sogou_sugg_feedbackquan" frameborder="0" scrolling="no" src="http://ht.www.sogou.com/websearch/features/yun1.jsp?pid=sogou-brse-596dedf4498e258e&w=1366&v=1401&st=1353139306998&od=17&ls=1353135638233&lc=&lk=&sd=8&cd=0&kd=0&u=1352951103835009&query=Google%20%E7%BF%BB%E8%AF%91|http%3A%2F%2Ftranslate.google.cn%2F%3Fhl%3Dzh-CN%26newwindow%3D1%26q%3Dguaranteed%26um%3D1%26ie%3DUTF-8%26sa%3DN%26tab%3DwT&r=http%3A%2F%2Fwww.google.com.hk%2Fsearch%3Fhl%3Dzh-CN%26%26newwindow%3D1%26q%3Dguaranteed" style="z-index:2147483645;border-bottom:medium none;border-left:medium none;line-height:38px;display:none;background:none transparent scroll repeat 0% 0%;border-top:medium none;border-right:medium none;"></iframe>


    Ellis_Wong

All Replies

  • Saturday, November 17, 2012 10:37 PM
    Answerer
     
     Proposed Answer

    The most likely reason is that there is a transaction lock issue. The pre and post plugin steps run inside a transaction, but your storedproc will be in a different one. This means that if you try to select any rows that are locked, you will get a timeout. Ideally you would write your storedproc to use the SDK. Otherwise, you could put your call in the prevalidation step or make the step asynchronous so that your SQL executes outside the CRM transaction.

     If you use SET TRANSACTION ISOLATION LEVEL READ UNCOMMITED in your storedproc, you could see if the problem is infact the locking.

    There is an unsupported way of using the same transaction as CRM - see http://www.develop1.net/public/post/SQL-Queries-from-Transactional-Plugin-Pipeline.aspx

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

  • Saturday, November 17, 2012 10:38 PM
     
     

    HI Ellis_wong,   

                    Are you registering your plugin in Sandbox mode? On that case try deploying it without that mode.


    Regards,
    Damian Sinay

  • Tuesday, November 27, 2012 9:18 PM
    Answerer
     
     
    How did you get on with this?

    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"