MySqlCommandBuilder.DeriveParameters: 指定的转换无效

MySqlCommandBuilder.DeriveParameters: Specified cast is not valid

我在 IIS/Windows 上使用 MySql.Data 版本 8.0.22 尝试连接到 MariaDB 10.4.12 (Linux)。我正在尝试使用 MySqlCommandBuilder.DeriveParameters 来获取参数信息:

        cmd.CommandText = "Mail_SaveEvent";
        cmd.CommandType = CommandType.StoredProcedure;
        MySqlCommandBuilder.DeriveParameters(cmd);

我存储的proc/routine有以下参数:

CREATE PROCEDURE shopmail_test.Mail_SaveEvent(
    IN inEventTypeID int,
    IN inEventDate datetime,
    IN inEventServer int,
    IN inEventTitle varchar(250),
    IN inEventText text,
    IN inEventMerchantID int,
    IN inEventAuditText text,
    IN inEventID int)
  SQL SECURITY INVOKER
  MODIFIES SQL DATA
BEGIN

我认为这可能是排序规则问题(我使用的是带有 utf8_unicode_ci 排序规则的 utf8),所以我注释掉了所有文本参数,甚至从例程主体中删除了大部分逻辑,但是我仍然收到以下错误:

12/4/2020 11:20 AM][Production  ]:          Specified cast is not valid.
[12/4/2020 11:20 AM][Production  ]:            at MySql.Data.MySqlClient.MySqlCommandBuilder.DeriveParameters(MySqlCommand command)

有趣的是,如果我尝试在托管在 Windows 框上的 MariaDB 10.4.17 上点击相同的 schema/routine,则该命令已正确填充。

这让我抓狂!有没有人遇到过这个问题并找到了解决方法?

这可能是 MySql.Data 中的一个错误(虽然我在 https://bugs.mysql.com/ 还没有看到相关报告)。你可以在那里报告它,并希望 Oracle 在未来的版本中修复它。

或者,切换到 MySqlConnector (disclaimer: lead author), which fixes a lot of MySql.Data bugs 并且与 MariaDB 具有很好的兼容性。