Reputation: 85
I am using Npgsql ADO dot net connector to communicate to postgresql from C# code.
Function is available in the postgresql DB, also I am able to execute it from pgadmin tool but unable to call it from c# code.
getting error
42883: function public.insert_json_array_to_test_method_temp(p_input_test_name => text, p_input_test_type_xref => text, p_input_unit_Attribute => text) does not exist"}
error hint - No function matches the given name and argument types. You might need to add explicit type casts.
Below is the C# code
NpgsqlConnection conn = new NpgsqlConnection(_connStr);
conn.Open();
NpgsqlCommand cmd = new NpgsqlCommand("public.insert_json_array_to_test_method_temp", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new NpgsqlParameter("p_input_test_name", NpgsqlDbType.Text) { Value = testmethod });
cmd.Parameters.Add(new NpgsqlParameter("p_input_test_type_xref", NpgsqlDbType.Text) { Value = testtypexref });
cmd.Parameters.Add(new NpgsqlParameter("p_input_unit_Attribute", NpgsqlDbType.Text) { Value = unitattributes });
NpgsqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
} conn.Close();
Below is the function header section
CREATE OR REPLACE FUNCTION
public.insert_json_array_to_test_method_temp(p_input_test_name
text,p_input_test_type_xref text,p_input_unit_attribute text)
RETURNS text
LANGUAGE 'plpgsql'
COST 100
VOLATILE
AS $BODY$
DECLARE res Text;
BEGIN
--some logic with parameters
res:= public."InsertTestNames"();
Return 'done';
END;
$BODY$;
Can any one please help what is the problem here ?
Upvotes: 1
Views: 769
Reputation: 85
I changed the way I was creating the parameters and was casting it - it's now working.
var parameter1 = cmd.CreateParameter();
parameter1.ParameterName = "parameter_name";
parameter1.NpgsqlDbType = NpgsqlDbType.Text;
parameter1.Value = parameter_value;
cmd.Parameters.Add(parameter1);
Upvotes: 2