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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:45:30+00:00 2026-06-04T08:45:30+00:00

I have a C# program I’m writing which interacts with SQL Server. I had

  • 0

I have a C# program I’m writing which interacts with SQL Server. I had foolishly hard-coded the query strings into the C# program, and wanted to instead turn those into Stored Procedures on the server.

For some reason, one particular INSERT statement (that was working fine!) no longer works and I can’t figure out why. I’ve even run a SQL Profiler Trace, and it shows that the statement is perfectly formed! Maybe someone can tell me what I’m doing wrong.

STORED PROCEDURE:
This SP just takes a bunch of parameters and inserts them into a table. Very simple.

ALTER PROCEDURE [dbo].[usp_InsertNewChangeRequest]

@Requester INT,
@ChangeCreationDate DATETIME,
@ChangeName VARCHAR(200),
@ChangeDescription VARCHAR(1000),
@LastModifiedDate DATETIME,
@LastModifiedBy INT,
@AffectedArea INT,
@ImplementationPlan VARCHAR(MAX),
@BackoutPlan VARCHAR(MAX),
@RiskLevel TINYINT,
@ApprovalRequired BIT,
@IsApproved BIT
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO dbo.ChangeRequests(Requester, ChangeCreationDate, ChangeName, ChangeDescription, 
            LastModifiedDate, LastModifiedBy, AffectedArea, ImplementationPlan, BackoutPlan, 
            RiskLevel, ApprovalRequired, IsApproved)
VALUES (@Requester, @ChangeCreationDate, @ChangeName, @ChangeDescription,
            @LastModifiedDate, @LastModifiedBy, @AffectedArea, @ImplementationPlan, @BackoutPlan,
            @RiskLevel, @ApprovalRequired, @IsApproved) 
END

My code in C# simply preps the SP parameters then calls a nonquery:

public int InsertNewChange(int RequesterID, DateTime CreationDate, string ChangeName,
        string ChangeDescription, DateTime LastModifiedDate, 
        int AffectedAreaID, string ImplementationPlan, string BackoutPlan,
        int RiskLevel, int ApprovalRequired, int IsApproved)
    {
        int retval = 0;

        // Create a command whose name is the stored procedure for inserts
        SqlCommand command = new SqlCommand("usp_InsertNewChangeRequest", scConnection);
        command.CommandType = CommandType.StoredProcedure;

        // add the parameters to the stored procedure
        command.Parameters.Add(new SqlParameter("@Requester", RequesterID));
        command.Parameters.Add(new SqlParameter("@ChangeCreationDate", CreationDate));
        command.Parameters.Add(new SqlParameter("@ChangeName", ChangeName));
        command.Parameters.Add(new SqlParameter("@ChangeDescription", ChangeDescription));
        command.Parameters.Add(new SqlParameter("@LastModifiedDate", LastModifiedDate));
        command.Parameters.Add(new SqlParameter("@LastModifiedBy", RequesterID));
        command.Parameters.Add(new SqlParameter("@AffectedArea", AffectedAreaID));
        command.Parameters.Add(new SqlParameter("@ImplementationPlan", ImplementationPlan));
        command.Parameters.Add(new SqlParameter("@BackoutPlan", BackoutPlan));
        command.Parameters.Add(new SqlParameter("@RiskLevel", RiskLevel));
        command.Parameters.Add(new SqlParameter("@ApprovalRequired", ApprovalRequired));
        command.Parameters.Add(new SqlParameter("@IsApproved", IsApproved));

        retval = command.ExecuteNonQuery();
        return retval;
    }

I’m constantly getting a -1 return value, whereas before, when I had the SQL text spelled out entirely in C#, I would get a 1, for the 1 row inserted.

Infuriatingly, I don’t see any error in SQL Profiler when doing a trace. It shows the statement passed, and it looks completely fine! When I cut and paste it into Management Studio and run it myself by hand, it works fine.

    exec usp_InsertNewChangeRequest @Requester=4,@ChangeCreationDate='2012-05-16 17:55:45',@ChangeName='test name',@ChangeDescription='test description',@LastModifiedDate='2012-05-16 17:56:01.937',@LastModifiedBy=4,@AffectedArea=2,@ImplementationPlan='test implem',@BackoutPlan='test backout',@RiskLevel=1,@ApprovalRequired=0,@IsApproved=0

Does anyone know why this would be happening to me? MANY THANKS!

  • 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-04T08:45:31+00:00Added an answer on June 4, 2026 at 8:45 am

    Because you turned it off:

    SET NOCOUNT ON;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok I have created a program which saves text into settings file. So at
I have program that constantly query a mysql server. Each time I access the
I have a program which I would like to run every X min the
I have a program which runs an external, command line utility and reads the
I have program which writes to database which folders are full or empty. Now
i have program which prints all char from char_min to char_max here is code
Here is my situation: I have program A which looks like this: Fmfile IF
I'm confused. I have program which I run as a non-administrator user. This program
I have program which reads MSMQ using GetAllMessages but it does not remove messages
I have a program that generates some standard SQL like SELECT * FROM TEST

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.