尝试针对 Db2 数据库使用 IBM.EntityFrameworkCore 运行存储过程时收到以下错误:
IBM.Data.Db2.DB2Exception (0x80004005): ERROR [42815] [IBM][AS] SQL0451N
The "1" definition, in the statement that defines routine "*N ",
contains a data type "FOOSCHEMA.FOONAME" that is not appropriate for a non-sourced routine
written in the given language or a routine that is defined as autonomous.
at IBM.Data.Db2.DB2Connection.HandleError(IntPtr hHandle, SQL_HANDLE hType, RETCODE retcode)
at IBM.Data.Db2.DB2Command.ExecuteNonQueryObject(Boolean skipInitialValidation)
at IBM.Data.Db2.DB2Command.ExecuteNonQueryObject()
at IBM.Data.Db2.DB2Command.ExecuteNonQuery()
我的逻辑如下
using var db2 = await db2Context.CreateDbContextAsync();
using var command = db2.Database.GetDbConnection().CreateCommand();
command.CommandText = "call FOOSCHEMA.FOONAME(?, ?, ?, ?, ?)";
command.CommandType = System.Data.CommandType.Text;
command.Parameters.Add(new DB2Parameter
{
ParameterName = "FooInputParam",
Value = "ST",
Direction = System.Data.ParameterDirection.Input,
DB2Type = DB2Type.Char,
Size = 2,
});
command.Parameters.Add(new DB2Parameter
{
ParameterName = "FooInputOutputParam",
Direction = System.Data.ParameterDirection.InputOutput,
DB2Type = DB2Type.Char,
Size = 500
});
/* 3 additional `Input` params redacted */
await db2.Database.OpenConnectionAsync();
var commandResult = await command.ExecuteNonQueryAsync(); // ERROR HERE
我做了一些搜索,但一无所获。我能够在我的环境中使用 IBM.EntityFrameworkCore 成功调用 Db2 中的其他存储过程。
下面是程序签名
有人知道我需要注意什么才能解决吗?
环境详情
通过消除过程,解决方法是确保对正在调用的例程进行编目。换句话说,目标例程出现在数据库目录中(在您的情况下,在
qsys2.routines
以及参数的所有相关表等中)。要对过程进行编目,请使用 create procedure
语句,并且当目标过程位于 RDBMS 外部时,请使用该语句的特定风格,如文档 here 中所述(请务必阅读所有相关页面,其中有很多)。
只有 IBM 可以说明这是一个 feature 还是一个 defect(如果是的话,具体在哪个组件中,可能不仅仅是他们的实体框架支持)'。因此,您应该向 IBM i-support 开具票证以获得答案,尽管您可能需要坚持不懈。然后您可以更新这个答案。 IBM 还可能建议其他不同的解决方法。
我确实知道,过去使用 Db2-LUW 产品(即不是 i 系列)可以调用未编目的外部过程,但几十年前 IBM 使这种做法变得更加困难或受到限制。近几十年来,我从不使用未编目的例程,无论脚手架/界面如何。
要跟踪驱动程序,请再次参考 IBM,因为跟踪详细信息会因驱动程序而异。这不是编程问题,而是文档问题,但通常能够在运行时跟踪 IBM 软件,以便确定问题。他们对 MS Entity Framework 的支持似乎是一个附加功能,文档很少,但我相信仍然是可追踪的。