I am trying to call a PostgreSQL stored procedure with OUT parameters from my .NET Core 3.1 API to delete a record based on an ID. However, when I attempt to execute the stored procedure with OUT parameters, I receive the following error:
42883: procedure usp_delete_announcements(integer) does not exist
Below is the relevant code block where I call the stored procedure with OUT parameters:
using (NpgsqlConnection conn = new NpgsqlConnection(connectionString))
{
conn.Open();
using (NpgsqlCommand cmd = new NpgsqlCommand("CALL usp_delete_announcements(@in_id)", conn))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@in_id", Convert.ToInt32(strDecryptedId));
cmd.Parameters.Add("@out_announcements_id", NpgsqlTypes.NpgsqlDbType.Integer).Direction = ParameterDirection.Output;
cmd.Parameters.Add("@out_error_code", NpgsqlTypes.NpgsqlDbType.Integer).Direction = ParameterDirection.Output;
cmd.Parameters.Add("@out_message", NpgsqlTypes.NpgsqlDbType.Varchar).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
response.Id = (int)cmd.Parameters["@out_announcements_id"].Value;
response.Message = cmd.Parameters["@out_message"].Value.ToString();
}
}
I need assistance with understanding why PostgreSQL is not recognizing when I try to call the stored procedure with OUT parameter, and I’d like to know if there's something wrong with the way I'm calling the procedure from .NET Core or if there’s an issue with my PostgreSQL setup.
Things I've Tried:
- Check Stored Procedure: I confirmed that the stored procedure exists and takes an integer parameter in PostgreSQL.
- Verify Parameters: I made sure that the input parameter
@in_id
is being passed correctly from C#. - Test Direct Execution: I tested the stored procedure directly in PostgreSQL to confirm that it works as expected with the input parameter.
What I Expected:
I expected the stored procedure to execute without issues, delete the record, and return the output parameters