且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用MySqlCommand执行存储过程时出现SqlNullValueException

更新时间:2023-02-07 09:35:52

这看起来像是Oracle的MySQL Connector/NET(也称为MySql.Data)中的错误.它看起来像我在该错误数据库中不熟悉的任何错误;它可能需要作为新的问题提交. (臭虫75301 看起来很相似,但并不清楚是同一问题. )

This looks like a bug in Oracle's MySQL Connector/NET (aka MySql.Data). It doesn't look like any bug that I'm familiar with in that bug database; it might need to be filed as a new issue. (Bug 75301 looks similar but it's not immediately obvious that it's the same issue.)

我建议切换到 MySqlConnector ;它是MySQL的备用ADO.NET库,与Dapper和修复了MySQL Connector/NET中的许多已知错误. MySqlConnector还具有真正的异步I/O支持,在连接器中未实现 /网;如果您想在代码中使用QueryAsync,这将很重要.

I would recommend switching to MySqlConnector; it's an alternate ADO.NET library for MySQL that has great compatibility with Dapper and fixes many known bugs in MySQL Connector/NET. MySqlConnector also has true async I/O support, which is not implemented in Connector/NET; this will be important if you want to use QueryAsync in your code.

如果您想继续使用Oracle的MySQL Connector/NET,则可以通过在连接字符串中添加CheckParameters=false来解决此问题.请注意,这可能是对代码的重大更改;如果将设置设置为false,则必须手动确保添加到每个CommandType.StoredProcedure MySqlCommand的参数与数据库的顺序完全相同(因为MySql.Data将不再为您修复它们)

If you want to keep using Oracle's MySQL Connector/NET, you may be able to work around the problem by adding CheckParameters=false to your connection string. Note that this could be a breaking change to your code; if you set the setting to false, you'll have to manually ensure that the parameters added to each CommandType.StoredProcedure MySqlCommand are in the exact same order as the database (because MySql.Data will no longer fix them up for you).

更新:查看了Connector/NET源代码后,看来您的数据库中包含一些意外数据.以下两个查询中的任何一个都会产生行吗?如果是,NULL是哪个值?

Update: After looking at the Connector/NET source code, it appears that your database has some data it's not expecting. Does either of the following two queries produce rows? If so, which value(s) are NULL?

SELECT * FROM information_schema.routines
WHERE specific_name IS NULL OR
    routine_schema IS NULL OR
    routine_name IS NULL OR
    routine_type IS NULL OR
    routine_definition IS NULL OR
    is_deterministic IS NULL OR
    sql_data_access IS NULL OR
    security_type IS NULL OR
    sql_mode IS NULL OR
    routine_comment IS NULL OR
    definer IS NULL;

SELECT * FROM mysql.proc
WHERE specific_name IS NULL OR
    db IS NULL OR
    name IS NULL OR
    type IS NULL OR
    body IS NULL OR
    is_deterministic IS NULL OR
    sql_data_access IS NULL OR
    security_type IS NULL OR
    sql_mode IS NULL OR
    comment IS NULL OR
    definer IS NULL;

您使用的是哪种MySQL Server(MySQL,MariaDB,Amazon Aurora)以及哪个版本?

What MySQL Server are you using (MySQL, MariaDB, Amazon Aurora) and which version?