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 7775701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:41:57+00:00 2026-06-01T17:41:57+00:00

I have an existing stored procedure in SQL Server that I need to call

  • 0

I have an existing stored procedure in SQL Server that I need to call from my C# code and get result. Here is how this SP looks like

CREATE PROCEDURE [dbo].[sp_MSnextID_DDB_NextID]
@tablesequence varchar(40)
AS
declare @next_id integer
begin transaction
update DDB_NextID
set DDB_SEQUENCE = DDB_SEQUENCE + 1
where DDB_TABLE = @tablesequence
select @next_id = DDB_SEQUENCE from DDB_NextID 
where DDB_TABLE = @tablesequence
commit transaction
RETURN @next_id

Here is my C# code

using (OdbcConnection connection = new OdbcConnection(GetConnectionString()))
{
   using (IDbCommand command = new OdbcCommand())
   {
      command.CommandText = "sp_MSnextID_DDB_NEXTID";
      command.CommandType = CommandType.StoredProcedure;
      IDbDataParameter parameter1 = command.CreateParameter();
      parameter1.DbType = DbType.String;
      parameter1.ParameterName = "@tablesequence";
      parameter1.Value = "ddb_dc_document";
      parameter1.Direction = ParameterDirection.Input;
      command.Parameters.Add(parameter1);

      IDbDataParameter parameter2 = command.CreateParameter();
      parameter2.DbType = DbType.Int32;
      parameter2.ParameterName = "@Return_Value";
      parameter2.Direction = ParameterDirection.ReturnValue;
      command.Parameters.Add(parameter2);
      command.Connection = connection;
      connection.Open();
      command.ExecuteNonQuery();
      IDbDataParameter o = (command.Parameters)["@Return_Value"] as IDbDataParameter;
      //Got return value from SP in o.Value
   }
}

The trouble is I am getting exception

[42000] [Microsoft][SQL Native Client][SQL Server]Procedure or function ‘sp_MSnextID_DDB_NextID’ expects parameter ‘@tablesequence’,
which was not supplied.

which I can’t explain or fix. What I am missing?

To find a way around, I was trying different approach: executing the following query that sets data in a temp table

create table #temp  (i integer); insert into #temp exec sp_MSNextID_DDB_NEXTID @tablesequence='ddb_dc_document';select * from #temp;

In this case SP is executed correctly but select returns zero rows!

  • 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-06-01T17:41:58+00:00Added an answer on June 1, 2026 at 5:41 pm

    Unfortunately, you can’t use named parameters with OdbcCommand. You will need to instead execute a call statement to your stored procedure.

    using (OdbcConnection connection = new OdbcConnection(GetConnectionString()))
    {
       using (IDbCommand command = new OdbcCommand())
       {
          command.CommandText = "{ ? = CALL sp_MSnextID_DDB_NEXTID(?) }";
          command.CommandType = CommandType.StoredProcedure;
    
    
          IDbDataParameter parameter2 = command.CreateParameter();
          parameter2.DbType = DbType.Int32;
          parameter2.ParameterName = "@Return_Value";
          parameter2.Direction = ParameterDirection.ReturnValue;
          command.Parameters.Add(parameter2);
    
          IDbDataParameter parameter1 = command.CreateParameter();
          parameter1.DbType = DbType.String;
          parameter1.ParameterName = "@tablesequence";
          parameter1.Value = "ddb_dc_document";
          parameter1.Direction = ParameterDirection.Input;
          command.Parameters.Add(parameter1);
    
          command.Connection = connection;
          connection.Open();
          command.ExecuteNonQuery();
          IDbDataParameter o = (command.Parameters)["@Return_Value"] as IDbDataParameter;
          //Got return value from SP in o.Value
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing SQL 2005 stored procedure that for some reason, outputs its
I have a stored procedure that finds all the existing databases and reads from
I have existing java code and need to create Design Document based on that.
I have a SQL Server 2008 database (call it productionDB) that contains data and
I am new to Transact SQL programming. I have created a stored procedure that
I have an already existing stored procedure. But when I am trying to create
We have an existing application that relies heavily on stored procedures and untyped DataSets.
I have existing code that uses CMNewProfileSearch to find then iterate over the color
I need to provide management with proof that a group of existing stored procedures
I'm writing a stored procedure in SQL Server 2008, interatively. When using SQL Server

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.