sp_executesql - Procedure or function expects parameter which was not supplied

后端 未结 3 1845
后悔当初
后悔当初 2021-01-18 13:17

I am working with Entity Framework in C# and am having an issue which I have tracked down to the SQL statement being generated.

The stored procedure takes in a table

3条回答
  •  无人共我
    2021-01-18 13:56

    You will have to specify the parameter mappings in your sql string for it to work. i.e in the C# code replace

    db.Database.SqlQuery("EXEC dbo.SaveResults", resultId, positiveResults) 
    

    with

    db.Database.SqlQuery("EXEC dbo.SaveResults @resultId=@resultId, @positiveResults=@positiveResults", resultId, positiveResults)
    

    It seems sp_executesql is unable to automatically associate the passed parameters to the expected parameters when executing a stored procedure unless the mappings are manually specified in the SQL string passed

提交回复
热议问题