I am trying to call a stored procedure from code and I get this error:
Error: 34000: cursor "<unnamed portal 1>" does not exist
My stored procedure:
Code: Select all
CREATE OR REPLACE FUNCTION public.getteamwork2(
ref refcursor)
RETURNS refcursor
LANGUAGE 'plpgsql'
COST 100.0
VOLATILE NOT LEAKPROOF
AS $function$
BEGIN
OPEN ref FOR
select tw.id, tw.date, tw.recipecode, sum(twd.quantity) as quantFinished, sum(tw.quantity) as quantInWork,
tw.idorder, tw.idemployee, tw.idteam, tw.itemcodeparent from teamwork tw
left join teamworkdetail twd on twd.idteamwork = tw.id
group by twd.idteamwork, tw.id, tw.date, tw.recipecode, tw.idorder, tw.idemployee, tw.idteam, tw.itemcodeparent
order by date desc;
RETURN ref; -- Return the cursor to the caller
END;
$function$;
Code: Select all
PgSqlConnection pgSqlConn = new PgSqlConnection();
pgSqlConn.ConnectionString = "User Id=xxx;Password=xxx;Host=xxx;database=xxx";
pgSqlConn.Open();
PgSqlCommand command = new PgSqlCommand("GetTeamWork2", pgSqlConn);
command.CommandType = CommandType.StoredProcedure;
command.ParameterCheck = true;
var reader = command.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);