7

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.

        SqlParameter param1 = new SqlParameter("@pNetworkHealthAssessmentID", pNetworkHealthAssessmentID);
        SqlParameter param2 = new SqlParameter("@pRiskAssessmentQuestionsID", pRiskAssessmentQuestionsID);
        SqlParameter param3 = new SqlParameter("@pUserID", UserID);
        SqlParameter param4 = new SqlParameter("@pSortOrder", pSortOrder);

        var result = db.Database.ExecuteSqlCommand("sp_RiskAssessmentQuestion_Copy2Network @pNetworkHealthAssessmentID, @pRiskAssessmentQuestionsID, @pUserID", "@pSortOrder",
                                      param1, param2, param3, param4)

The Stored procedure's arguments look like this:

 CREATE PROCEDURE [dbo].[sp_RiskAssessmentQuestion_Copy2Network] (
 @pNetworkHealthAssessmentID bigint
,@pRiskAssessmentQuestionsID bigint
,@pUserID bigint
,@pSortOrder int
)

Stored Procedure doesn't return any value back. Why am I getting that exception? I have tried every possible solution but so far unsuccessful

1

1 Answer 1

9

You are not including that last parameter, "pSortOrder" was separated by a comma and it should be a part of the first string.

var result = db.Database.ExecuteSqlCommand("sp_RiskAssessmentQuestion_Copy2Network @pNetworkHealthAssessmentID, @pRiskAssessmentQuestionsID, @pUserID, @pSortOrder"
, param1, param2, param3, param4)
Sign up to request clarification or add additional context in comments.

2 Comments

Ohh I see what I'm doing wrong. Spent hours on this and didn't notice it.
@AhmedMujtaba - glad it helped. Please consider marking it as answer if it solved your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.