I am trying to execute a stored procedure (against SQL Server 2005 using the ODBC driver) and I am getting the following error:
The procedure or function "GetNodeID" expects the parameter "@ID", which was not provided.
@ID is the OUTPUT parameter for my procedure, there is an @machine input file that is specified and set to null in the stored procedure:
ALTER PROCEDURE [dbo].[GetNodeID] @machine nvarchar(32) = null, @ID int OUTPUT AS BEGIN SET NOCOUNT ON; IF EXISTS(SELECT * FROM Nodes WHERE NodeName=@machine ) BEGIN SELECT @ID = (SELECT NodeID FROM Nodes WHERE NodeName=@machine ) END ELSE BEGIN INSERT INTO Nodes (NodeName) VALUES (@machine) SELECT @ID = (SELECT NodeID FROM Nodes WHERE NodeName=@machine ) END END
Below is the code that I use to set the parameters and call the procedure:
OdbcCommand Cmd = new OdbcCommand("GetNodeID", _Connection); Cmd.CommandType = CommandType.StoredProcedure; Cmd.Parameters.Add("@machine", OdbcType.NVarChar); Cmd.Parameters["@machine"].Value = Environment.MachineName.ToLower(); Cmd.Parameters.Add("@ID", OdbcType.Int); Cmd.Parameters["@ID"].Direction = ParameterDirection.Output; Cmd.ExecuteNonQuery(); _NodeID = (int)Cmd.Parameters["@Count"].Value;
I also tried using Cmd.ExecuteScalar without success. If I break before executing the command, I see that the @machine value matters.
If I execute the procedure directly from Management Studio, it works correctly.
Any thoughts? Thanks
Aaron
source share