netcore6使用postgresql执行存储过程如何获取返回的游标 返回

SqlSugar 沟通中
8 1018

netcore6使用postgresql执行存储过程返回游标 cursor "<unnamed portal 1>" does not exist

image.png

热忱回答8

  • fate sta fate sta VIP0
    2025/9/14

    写出ADO.NET怎么获取。我这边提供sqlsugar如何获取代码。

    0 回复
  • image.png

    0 回复
  • @fate sta:这么写的

    0 回复
  • @fate sta:帮我看看这个问题

    多谢

    0 回复
  • fate sta fate sta VIP0
    2025/9/15

    p.CustomDbType=NpgsqlDbType.Refcursor;

    0 回复
  • fate sta fate sta VIP0
    2025/9/15

    另外开启事务保证是一个长链接

    0 回复
  • fate sta fate sta VIP0
    2025/9/15

    文档入门有3种长链接写法

    0 回复
  • OK解决了

     public async Task<DataTable> QueryProc(string procName, List<SugarParameter> dbParameters = null)

     {

         BeginTrans();

         try

         {

             DataTable dt = new DataTable();

             TenantHelper.AddParam(dbParameters, this._isTenant);

             await _orm.Ado.UseStoredProcedure().GetDataTableAsync(procName, dbParameters);

             foreach (var item in dbParameters)

             {

                 if (item.IsRefCursor)

                 {

                     // 4. 获取游标并读取数据

                     var cursor = item.Value; // 提取游标对象

                     var reader = _orm.Ado.GetDataReader("FETCH ALL IN \"" + cursor + "\""); // 处理游标数据

                     dt.Load(reader);

                 }

             }

             Commit();

             return DBCommonHelper.DtColToLow(dt);

         }

         catch (Exception ex)

         {

             Rollback();

             throw ex;

         }

     }


    0 回复