Hi
I have a stored procedure that inserts and returns a value.
I've been able to execute the procedure and I get the return value but the
INSERT is not working. I'm getting no errors. Why is the INSERT not firing in my stored Procedure?
I've checked the Permissions on the tables and the procedures as well and it has rights for INSERTING
I have a stored procedure that inserts and returns a value.
I've been able to execute the procedure and I get the return value but the
INSERT is not working. I'm getting no errors. Why is the INSERT not firing in my stored Procedure?
I've checked the Permissions on the tables and the procedures as well and it has rights for INSERTING
C#:
/***************Stored Procedure***********************/
USE [testDataBase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[MakeValue]
(
@timeLive smallint
)
AS
BEGIN
SET NOCOUNT ON
DECLARE @CookieID varchar(50)
SET @CookieID = NEWID()
INSERT INTO dbo.Sessions (CookieID, TTL,LastVisit) VALUES (@CookieID, @timeLive,CURRENT_TIMESTAMP)
IF @@ERROR = 0 AND @@ROWCOUNT = 1
BEGIN
SELECT @CookieID AS '@@CookieID'
RETURN 0
END
ELSE
BEGIN
RAISERROR('Something went wrong :-(', 16, 1)
RETURN -1
END
END
C#:
public static void SessionStoredProcedure()
{
if (sessionID.Length < 1)
{
int sessionTimeOut = 15;
if (StdVariables.sqlConn1.State == ConnectionState.Closed)
{
StdVariables.sqlConn1.Open();
}
using (SqlConnection con = new SqlConnection(StdVariables.connStr))
{
using (SqlCommand cmd = new SqlCommand("CreateSessionID", StdVariables.sqlConn1))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@TTL", SqlDbType.Int).Value = sessionTimeOut;
con.Open();
cmd.ExecuteScalar();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
if (reader.HasRows)
{
sessionID = reader["@@SessionID"].ToString();
}
}
}
}
}
}
Last edited: