Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 621
Ahmed Mujtaba Avatar asked Apr 09 '17 10:04

Ahmed Mujtaba


1 Answers

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)
like image 161
Igor Avatar answered Nov 15 '22 00:11

Igor