0
CREATE PROCEDURE GetActiveServerURL
(
@ActiveURL VARCHAR(100) OUTPUT
)
AS
BEGIN
SELECT @ActiveURL = RedirectURL FROM HealthCheck WHERE IsPrimary=1 AND Status=1
END

Error Message : Procedure or function 'GetActiveServerURL' expects parameter '@ActiveURL', which was not supplied.


As I have declared ActiveURL as output parameter stil it expects as input

2
  • EXEC GetActiveServerURL @ActiveURL OUTPUT Commented Mar 26, 2014 at 15:07
  • It should be something like DECLARE @ActiveURL VARCHAR(100); EXEC GetActiveServerURL @ActiveURL OUTPUT ; Commented Mar 26, 2014 at 15:14

3 Answers 3

1

You must mention in your call that the parameter is output also.

DECLARE @ActiveURL VARCHAR(100)
EXEC GetActiveServerURL @ActiveURL OUTPUT

Here how to execute SP from C#

string activeURL;

using(var conn = new SqlConnection(connectionString))
using(var command = new SqlCommand())
{
   command.Connection = conn;
   command.CommandText = "GetActiveServerURL";
   command.CommandType = CommandType.StoredProcedure;

   SqlParameter param = new SqlParameter("@ActiveURL", SqlDbType.VarChar, 100);
   param.Direction = ParameterDirection.Output,
   command.Parameters.Add(param);
   conn.Open();
   command.ExecuteNonQuery();

   activeURL = param.Value;
}
Sign up to request clarification or add additional context in comments.

3 Comments

When I call as EXEC GetActiveServerURL @ActiveURL OUTPUT.. again it is saying that : Must declare the scalar variable "@ActiveURL".
Do you see the first line in my post? Show more code.How you call the SP?
yeah I have seen it. Now How Call That procedure fron c#. Do I need to simply say cmd.CommandText = "GetActiveServerURL"; or anything else
0

You need to call the procedure with a parameter and include the OUTPUT directive.

SET @ActiveURL = 'http://'

EXEC GetActiveServerURL @ActiveURL OUTPUT

Comments

0
CREATE PROCEDURE GetActiveServerURL
(
 DECLARE @ActiveURL VARCHAR(100) OUTPUT
)
AS
BEGIN
SELECT @ActiveURL = RedirectURL FROM HealthCheck WHERE IsPrimary=1 AND Status=1
END  

EXEC GetActiveURL @ActiveURL OUTPUT



      Error : Incorrect syntax near the keyword 'DECLARE'.

Msg 102, Level 15, State 1, Procedure GetActiveServerURL, Line 3 Incorrect syntax near 'OUTPUT'. Msg 137, Level 15, State 1, Procedure GetActiveServerURL, Line 7 Must declare the scalar variable "@ActiveURL"

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.