I have a C # program that I am writing that interacts with SQL Server. I stupidly encoded the query strings in a C # program and wanted to include them in the stored procedures on the server instead.
For some reason, one particular INSERT statement (which works fine!) No longer works, and I can't figure out why. I even run SQL Profiler Trace, and it shows that the statement is perfectly formed! Maybe someone can tell me what I'm doing wrong.
REMEMBERED PROCEDURE: This SP simply takes a set of parameters and inserts them into the 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 adjusts the SP parameters and then calls the request:
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;
SqlCommand command = new SqlCommand("usp_InsertNewChangeRequest", scConnection);
command.CommandType = CommandType.StoredProcedure;
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;
}
-1, , SQL, #, 1, 1 .
, SQL Profiler . , , ! Management Studio , .
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
- , ? !