1

I am calling a stored procedure and declare an output paramters:

CREATE PROCEDURE dbo.usp_getIsReadyForProcess
@VideoId INT ,
@val INT OUTPUT
AS
BEGIN
BEGIN TRY
    BEGIN TRANSACTION
-- LOCK ROW UNTIL END OF TRANSACTION
        SELECT * FROM dbo.ProcessStatus WITH (ROWLOCK, HOLDLOCK) WHERE VideoId = @VideoId

And then setting the value throughout the transaction

  --If there is no row count
IF @@ROWCOUNT = 0
BEGIN
    SET @val = 0
END

-- If video is already in process
ELSE IF @statusCode > 1
BEGIN
    SET @val = 0
END

...... more if blocks

          -- RELEASE LOCK
    COMMIT TRANSACTION
END TRY   

Here is the c# code for getting the output parameter:

        using (var db = EntityFactory.GetInstance())
        {
            ObjectParameter objParam = new ObjectParameter("val", typeof(int));
            db.usp_getIsReadyForProcess(videoId, objParam);

            return (int)objParam.Value == 1;
        }

... But then objParam.Value is null no matter what I do.

So I dig a little deeper and uncover an exception that was handled already,

Message: Method may only be called on a Type for which Type.IsGenericParameter is true.

What am i doing wrong? I tried type(bool, int32, string) .. nothing works

3
  • I'm not sure EF supports output parameters. Commented Feb 22, 2015 at 22:56
  • 1
    Have you looked at this post: stackoverflow.com/questions/5881359/… Commented Feb 22, 2015 at 23:00
  • @DavidTansey Hmm, good link. So you need to ensure the procedure has executed before checking the return value. Commented Feb 22, 2015 at 23:03

1 Answer 1

1

Your stored procedure returns a resultset, due to this line:

SELECT * FROM dbo.ProcessStatus WITH (ROWLOCK, HOLDLOCK) WHERE VideoId = @VideoId

You can either change the SQL to something like:

DECLARE @RowCount INT
SELECT @RowCount = COUNT(*) FROM dbo.ProcessStatus WITH (ROWLOCK, HOLDLOCK) WHERE VideoId = @VideoId

Or you can capture the resultset in your code:

var resultSet = db.usp_getIsReadyForProcess(videoId, objParam);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.