Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7619757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:46:04+00:00 2026-05-31T03:46:04+00:00

I am calling a stored procedure from a DbContext using SqlQuery() . When I

  • 0

I am calling a stored procedure from a DbContext using SqlQuery(). When I run the query I get the error Procedure or function 'p_Insert_Phones' expects parameter '@Number', which was not supplied. What am I missing here? I see the @Number parameter.

declare @p5 nvarchar(255)

set @p5=NULL

exec sp_executesql N'p_Insert_Phones',
     N'@Number int,
     @PhoneTypeId int,
     @ReturnId nvarchar(255) output',
     @Number=0,
     @PhoneTypeId=0,
     @ReturnId=@p5 output

select @p5

EDIT

Procedure definition

CREATE PROCEDURE [dbo].[p_Insert_Phones]
(
    @Number int,
    @PhoneTypeId int,
    @ReturnId uniqueidentifier out
) 
AS 
DECLARE @id TABLE(
    ReturnColId uniqueidentifier
) 

BEGIN TRAN 
    INSERT INTO Phones ([Number],[PhoneTypeId]) 

    OUTPUT inserted.Id 
    INTO @id 
    VALUES (@Number,@PhoneTypeId) 
COMMIT TRAN 

SET @ReturnId = (SELECT ReturnColId FROM @id)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:46:05+00:00Added an answer on May 31, 2026 at 3:46 am

    You cannot call a stored procedure that is found in the database. The parameters that you provide will not be found by the stored procedure. I resolved the issue by including the stored procedure as the sql in the DbContext call.

    var sqlInsert = "DECLARE @id TABLE(ReturnColId uniqueidentifier) " + 
    "BEGIN TRAN INSERT INTO Phones " +
        "([Number],PhoneTypeId]) " +
        "OUTPUT inserted.Id " +
        "INTO @id " +
        "VALUES (@Number,@PhoneTypeId) " +
    "COMMIT TRAN " +
    
    "SET @ReturnId = (SELECT ReturnColId FROM @id)"
    
    var sqlTransaction = context.Database.SqlQuery(type, insertProcedure, parameters.ToArray());
    
    foreach (var record in sqlTransaction) { } // executes the lazy loading in order to
                                               // populate the out parameter.
    
    Guid newId = new Guid(parameters[parameters.Count - 1].Value.ToString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using NHibernate and calling a stored procedure via a named query: <sql-query
I am calling a stored procedure using a text query for the dataset using
I am calling a SQL Server stored procedure from my C# code: using (SqlConnection
I'm getting the following error when calling a stored procedure: Cannot find the object
HI I am getting this exception when I am calling any stored procedure from
When calling a stored procedure from vb.net is there a default SQL timeout time
I'm calling a stored procedure from C# .net and one of the string parameters
I am calling a stored procedure from another stored procedure. That stored procedure is
From PHP, I am calling a SQL stored procedure. The stored procedure checks the
How can I ignore an output parameter of a stored procedure? I'm calling the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.