locked
ExecuteStoreQuery throwing InvalidOperationException RRS feed

  • Question

  • When I run the following ExecuteStoreQuery consitently throws an InvalidOperationException with the following message:

    When executing a command, parameters must be exclusively database parameters or values.

    I've tried a few differenent things and I don't know what's going on.  I'd rather not inline the parameters in the SQL if possible.  When I pass only one parameter it works fine.  Any help would be appreciated.

    string sql = @"exec [usp_SEL_CIRCT__DVSN] @ST_CD = @stateCode @DVSN_NM = @name";
    SqlParameter stateCodeParam = new SqlParameter ( "@stateCode", division.StateCode );
    SqlParameter nameParam   = new SqlParameter ( "@name", division.Name );
    ObjectResult<Circuit> result = _objCtx.ExecuteStoreQuery<Circuit> ( sql, EntitySetName, stateCodeParam, nameParam );
    return new List<Circuit> ( result );
    

     

    Friday, November 12, 2010 1:51 PM

Answers

  • Nevermind, I forgot my MergeOption which trigger the EntitySetName string to be taken in as a parameter. 
    • Marked as answer by Jon Theriault Friday, November 12, 2010 9:50 PM
    Friday, November 12, 2010 9:50 PM

All replies

  • Hi,

    What happens if you add a , character between @stateCode and @DVSN_NM to separate arguments ?


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
    Friday, November 12, 2010 2:09 PM
  • Nice catch.  I must have left it off in all my playing around with the command text.  Same thing happens with or without the comma.  It looks like the error is being thrown before the DataReader calls the database. 

    • Proposed as answer by Nilesh Gadhiya Wednesday, February 10, 2016 2:22 PM
    Friday, November 12, 2010 2:14 PM
  • Nevermind, I forgot my MergeOption which trigger the EntitySetName string to be taken in as a parameter. 
    • Marked as answer by Jon Theriault Friday, November 12, 2010 9:50 PM
    Friday, November 12, 2010 9:50 PM
  • Hello Jon,

    Thanks for sharing the solution with community members. It's really helpful to others having the same issue.

    Have a nice day!


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Monday, November 15, 2010 2:47 AM