Retrieving Database procedure value with Provider
I am trying to retrieve data from my database procedure but I'm not sure
why I'm getting a return value of -1 when a value of 1 or 0 is supposed to
be returned. I feel as thought everything is being passed in correctly and
the procedure is running well. But I could be wrong.
I pass an object with the name of "Status" of type int into my database
procedure db.proc_CsStatus and db.proc_GhStatus. During the debugger
though I get "r" a value of -1.
My Controller:
public ActionResult Index()
{
ViewBag.CsStatus = GhCsStatusProvider.GetCsStatus();
ViewBag.GhStatus = GhCsStatusProvider.GetGhStatus();
return View();
}
My provider has these two functions:
public static int GetGhStatus()
{
using (Entities db = new Entities())
{
System.Data.Objects.ObjectParameter s = new
System.Data.Objects.ObjectParameter("Status",
typeof(int));
int r = db.proc_CsStatus(120, s);
return r;
}
}
public static int GetCsStatus()
{
using (Entities db = new Entities())
{
System.Data.Objects.ObjectParameter s = new
System.Data.Objects.ObjectParameter("Status",
typeof(int));
int r = db.proc_CsStatus(120, s);
return r;
}
}
Here are my database procedures:
For proc_GhStatus
USE [DATABASE_GH]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[proc_GhStatus]
-- Add the parameters for the stored procedure here
@TimeLimit Int,
@Status Int OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON
-- Declare variables.
DECLARE @LastUpdate Int
-- Calculate the LastUpdate.
SELECT @LastUpdate = DATEDIFF(second, Timestamp, CURRENT_TIMESTAMP)
FROM Heartbeat
WHERE Id=2
-- Compare it to the TimeLimit.
IF @LastUpdate > @TimeLimit SELECT @Status = 0
ELSE SELECT @Status = 1
END
GO
For CsStatus
USE [DATABASE_CS]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[proc_GhStatus]
-- Add the parameters for the stored procedure here
@TimeLimit Int,
@Status Int OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON
-- Declare variables.
DECLARE @LastUpdate Int
-- Calculate the LastUpdate.
SELECT @LastUpdate = DATEDIFF(second, Timestamp, CURRENT_TIMESTAMP)
FROM Heartbeat
WHERE Id=2
-- Compare it to the TimeLimit.
IF @LastUpdate > @TimeLimit SELECT @Status = 0
ELSE SELECT @Status = 1
END
GO
No comments:
Post a Comment