How to call the Postgres V11 Stored Procedures(not function) with InOut parameter as RefCursor? using Npgsql v4.0.8

*爱你&永不变心* 提交于 2021-01-29 08:34:43

问题


I am trying to call the postgresql v11 store procedure (not function) with InOut parameter as RefCursor? using Npgsql v4.0.8 from ado.net code 4.5 framework. but not able to read the data from it.

even have tried using Npgsql v4.1.2(latest version) from ado.net code 4.6.1 framework also but still then not able to read the data from store procedure.

what is the solution? for it. please provide sample code to fetch the value.

my sample code:

public void PopulateTableFromCursor()
   {
       OpenConnection();

       NpgsqlDataAdapter adapter = new NpgsqlDataAdapter();
       NpgsqlCommand command = this.Connection.CreateCommand();

       NpgsqlParameter paRef1 = new NpgsqlParameter("@ref1", NpgsqlTypes.NpgsqlDbType.Refcursor);
       paRef1.Direction = ParameterDirection.InputOutput;
       paRef1.Value = "ref1";
       command.Parameters.Add(paRef1);          
       command.CommandTimeout = 60000;          
       command.CommandText = "call public.sp_admin_getconfiguredusers('ref1');fetch all \"ref1\"";

       try
       {
           command.ExecuteNonQuery();
           var result = paRef1.Value;

       }            
       catch (Exception ex)
       {
           throw new Exception(ex.Message);              
       }
       finally
       {
           this.Connection.Close();
       }
   }

来源:https://stackoverflow.com/questions/58979996/how-to-call-the-postgres-v11-stored-proceduresnot-function-with-inout-paramete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!