Sybase迁移至SQL Server后,ESQL调用存储过程无法返回值至ESQL List
Sybase迁移至SQL Server后ESQL调用存储过程无返回值问题排查
将底层数据库从Sybase迁移到SQL Server后,原Sybase上正常运行的ESQL代码失效:调用存储过程后,预期存入返回值的ESQL列表未获取到任何数据。相关代码如下:
while I < n Declare MyList reference to Environment.XMLNSC.MyData.LIST[I]; Create Field Enviornment.XMLNSC.MyData.LIST[I].GetParams; Call MyParamsFunctionESQL (MyList, Enviornment.XMLNSC.MyData.LIST[I]GetParams); //Here's is the definition of MyParams Funcion Create Procedure MyParamsFunctionESQL (In List1 Reference, In Params) Begin Declare Value1, Value2 Integer; Set Value1 = CAST(List1.Value1 AS Integer); Set Value2 = CAST(List1.Value2 AS Integer); //Here's the call for DB stored procedure functon Call MyParamsFunction(Value1, Value2, Params.GetMyParams[]) IN database.(getDNS("MyDSN")).dbo END; // Here's the definition for the stored procedure Create Procedure MyParamsFunction ( IN Value1 Integer; IN Value2 Integer; ) Language Database Dynamic Result Set 1 External Name "dbo.MyParamsFunction"
问题点及解决办法
- 参数数量不匹配:ESQL存储过程
MyParamsFunction仅声明2个输入参数,但调用时传入了3个参数,直接导致调用失败无法返回结果。需在存储过程定义中新增对应输出参数接收结果集。 - 拼写错误:代码中
Enviornment为拼写错误,正确应为Environment,该错误会导致字段创建失败,后续参数传递自然无法获取值。 - 参数传递方向错误:调用
MyParamsFunctionESQL时传入的Params参数仅声明为In,无法接收存储过程返回的结果,需改为InOut类型。 - SQL Server结果集处理差异:Sybase与SQL Server对存储过程结果集的绑定逻辑有差异,需确保ESQL参数与SQL Server存储过程的返回结果正确映射。
修正后的代码示例
修正参数定义的ESQL存储过程
Create Procedure MyParamsFunction ( IN Value1 Integer; IN Value2 Integer; OUT GetMyParams[]; -- 新增输出参数用于接收结果集 ) Language Database Dynamic Result Set 1 External Name "dbo.MyParamsFunction"
修正调用逻辑与拼写错误的主代码
while I < n Declare MyList reference to Environment.XMLNSC.MyData.LIST[I]; Create Field Environment.XMLNSC.MyData.LIST[I].GetParams; -- 修正拼写错误 Call MyParamsFunctionESQL (MyList, Environment.XMLNSC.MyData.LIST[I].GetParams); -- 补全GetParams前的点号 // MyParamsFunctionESQL定义 Create Procedure MyParamsFunctionESQL (In List1 Reference, InOut Params) -- 修改参数传递方向 Begin Declare Value1, Value2 Integer; Set Value1 = CAST(List1.Value1 AS Integer); Set Value2 = CAST(List1.Value2 AS Integer); -- 匹配参数数量,用Params.GetMyParams接收结果 Call MyParamsFunction(Value1, Value2, Params.GetMyParams[]) IN database.(getDNS("MyDSN")).dbo; END;
额外检查项
- 在SSMS中直接执行SQL Server端的
dbo.MyParamsFunction,确认其能正常返回结果集。 - 验证
getDNS("MyDSN")指向的SQL Server连接字符串配置正确,数据库用户具备执行存储过程及读取结果的权限。 - 查看ESQL运行日志,排查是否存在参数类型不匹配、权限不足等报错信息。
内容的提问来源于stack exchange,提问作者WENzER
相关产品推荐
相关产品推荐

