sp_executesql - Procedure or function expects parameter which was not supplied

后端 未结 3 1878
后悔当初
后悔当初 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:50

    You're using sp_executesql to run the SQL text dbo.SaveResults. This T-SQL runs the procedure dbo.SaveResults with no parameters. Now you understand where that message comes from. What to do about it? Use EXEC:

    EXEC dbo.SaveResults @resultID = 1234, @positiveResults = @p3
    

    Or, nest the call:

    exec sp_executesql N'
    
        EXEC dbo.SaveResults @resultID = @resultID, @positiveResults = @positiveResults
    
    ',N'@resultID int, @positiveResults [PositiveTypes] READONLY',@resultID=1,@positiveResults=@p3
    

    I have indented to make it more clear. The 2nd variant is not useful as far as I can tell. Use the first one.

提交回复
热议问题