为了账号安全,请及时绑定邮箱和手机立即绑定

MySql.Data.MySqlClient.MySqlException (0x80004005)

MySql.Data.MySqlClient.MySqlException (0x80004005)

C#
弑天下 2021-06-18 15:34:51
我正在使用 Dapper 来调用 MySql 存储过程。该过程执行得很好,但之后代码抛出异常。有问题的代码块是这样的:    using (var conn = DataFactory.InitializeConnection(false))    {        conn.Query("ProcedureName", new        {            puserid = ID        }, commandType: System.Data.CommandType.StoredProcedure);    }DataFactory以下静态类在哪里:public static class DataFactory{    public static IDbConnection InitializeConnection(bool open = true, string connectionstring = "", string databaseServerType = "MYSQL")    {        if (string.Equals(databaseServerType, "MYSQL"))        {            if (string.IsNullOrEmpty(connectionstring))                connectionstring = Settings.Default.DataConnectionString;            var csb = new MySql.Data.MySqlClient.MySqlConnectionStringBuilder(connectionstring);            var conn = new MySql.Data.MySqlClient.MySqlConnection(csb.ConnectionString);            Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;            if (open)                conn.Open();            return conn;        }        throw new NotImplementedException("Not implemented for your database provider");    }}bogus_table我的数据库中没有,但它显示在错误消息中:MySql.Data.MySqlClient.MySqlException (0x80004005): 在 MySql.Data.MySqlClient.MySqlStream.ReadPacket() 的 MySql.Data.MySqlClient.NativeDriver.GetResult 处的表'bogus_table' 的SELECT 命令拒绝用户 'XXX'@'YYY'在 MySql.Data.MySqlClient.MySqlDataReader.NextResult() 在 MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior 行为) 的 MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) (Int32&fluenceRow, Int64&insertId)在 MySql.Data.MySqlClient.MySqlDataReader.ClearKillFlag() 在 MySql.Data.MySqlClient.MySqlDataReader.Close() 在 MySql.Data.MySqlClient.MySqlDataReader.Dispose(Boolean disposing)在 MySql.Data.MySqlClient.MySqlDataReader.Dispose()在 Dapper.SqlMapper.d__136 1.<>m__Finally1()    at  Dapper.SqlMapper.<QueryImpl>d__1361.移动下一步()
查看完整描述

1 回答

?
慕斯王

TA贡献1864条经验 获得超2个赞

这可能是Mysql Driver实现中的问题 ;这是提到bogus_table 的代码块。如果您的过程有空结果,请尝试使用 Execute 调用(因为它在内部实现了执行非查询) 而不是 Query。


using (var conn = DataFactory.InitializeConnection(false))

    {

        conn.Execute("ProcedureName", new

        {

            puserid = ID

        }, commandType: System.Data.CommandType.StoredProcedure);

    }


查看完整回答
反对 回复 2021-06-20
  • 1 回答
  • 0 关注
  • 1831 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信