ensleep
ensleep

Reputation: 11

mysql.data 8.0 occurs "Parameter '-' not found in the collection" in .net core 3.1 when call PROCEDURE

mysql.data 8.0 occurs "Parameter '-' not found in the collection" in .net core 3.1 when call PROCEDURE.But it ok when I make "CheckParameters=false".But I don't want CheckParameters to be false.

my enviranment is :

asp.net core 3.1 mysql.data in installed from nuget and the version is 8.0.20 the database is in cloud of tencent and is

my sp code is :

CREATE PROCEDURE `sp_Sys_Option_Select_Test`(
    IN  INKEYWORD               VARCHAR(50),        --  关键字
    IN  INPAGESIZE              VARCHAR(50),            --  每页行数
    IN  INCURPAGE               VARCHAR(50),            --  当前页数
    IN  USERCODE                    VARCHAR(50),        --  操作人编码       (*)
    OUT OUTTOTALCOUNT       VARCHAR(50),            --  总行数
    OUT OUTCHECKMESSAGE VARCHAR(500)        --  返回消息
)
BEGIN 
    select now() as dttime;
    SET OUTTOTALCOUNT = 'this is out_TotalCount';
    SET OUTCHECKMESSAGE = 'Y:控制开关查询成功(反馈';
END

and my c# in asp.net core 3.1 is :


using (var conn= new MySql.Data.MySqlClient.MySqlConnection(ConnectionString))
{
    MySqlCommand myCommand = new MySqlCommand("sp_Sys_Option_Select_Test", conn);
    myCommand.CommandType = System.Data.CommandType.StoredProcedure;
    myCommand.Parameters.Add(new MySqlParameter() { ParameterName = "INKEYWORD", Value = "", Direction = ParameterDirection.Input, DbType = System.Data.DbType.String });
    myCommand.Parameters.Add(new MySqlParameter() { ParameterName = "INPAGESIZE", Value = "2", Direction = ParameterDirection.Input, DbType = System.Data.DbType.String });
    myCommand.Parameters.Add(new MySqlParameter() { ParameterName = "INCURPAGE", Value = "1", Direction = ParameterDirection.Input, DbType = System.Data.DbType.String });
    myCommand.Parameters.Add(new MySqlParameter() { ParameterName = "USERCODE", Value = "ADMIN", Direction = ParameterDirection.Input, DbType = System.Data.DbType.String });
    myCommand.Parameters.Add(new MySqlParameter() { ParameterName = "OUTTOTALCOUNT", Value = null, Direction = ParameterDirection.Output, DbType = System.Data.DbType.String, Size = 4000 });
    var outp = new MySqlParameter() { ParameterName = "OUTCHECKMESSAGE", Value = null, Direction = ParameterDirection.Output, DbType = System.Data.DbType.String, Size = 4000 };
    myCommand.Parameters.Add(outp);
    MySqlDataAdapter mda = new MySqlDataAdapter(myCommand);
    DataSet ds = new DataSet();
    mda.Fill(ds);
    Console.WriteLine(Convert.ToString(outp.Value));
}

you can see my parameters without '@'.Actually,it is then same error when I add '@' to the parameter. then the exception is :

   at MySql.Data.MySqlClient.MySqlParameterCollection.GetParameterFlexible(String parameterName, Boolean throwOnNotFound)
   at MySql.Data.MySqlClient.StoredProcedure.GetAndFixParameter(String spName, MySqlSchemaRow param, Boolean realAsFloat, MySqlParameter returnParameter)
   at MySql.Data.MySqlClient.StoredProcedure.CheckParameters(String spName)
   at MySql.Data.MySqlClient.StoredProcedure.Resolve(Boolean preparing)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   at EcCloudCoreApi.Program.CreateHostBuilder(String[] args) in 

Upvotes: 0

Views: 458

Answers (1)

Bradley Grainger
Bradley Grainger

Reputation: 28182

This sounds like a bug in Oracle's MySQL Connector/NET (i.e., MySql.Data). If you can find a small repro, you can report it at https://bugs.mysql.com. (I wasn't able to reproduce the problem with the code you provided, using MySQL Server.)

You should be able to work around the problem by switching to MySqlConnector, an alternate MySQL ADO.NET library. Instructions for migrating are here: https://mysqlconnector.net/tutorials/migrating-from-connector-net/

Upvotes: 1

Related Questions