微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – MySql.Data.MySqlClient.MySqlException(0x80004005):SELECT命令被拒绝用户’XXX’@’YYY’用于表’bogus_table’

我正在使用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): SELECT command
denied to user ‘XXX’@’YYY’ for table ‘bogus_table’ at
MysqL.Data.MysqLClient.MysqLStream.ReadPacket() at
MysqL.Data.MysqLClient.NativeDriver.GetResult(Int32& affectedRow,
Int64& insertedId) at
MysqL.Data.MysqLClient.Driver.NextResult(Int32 statementId,Boolean
force) at MysqL.Data.MysqLClient.MysqLDataReader.NextResult() at
MysqL.Data.MysqLClient.MysqLCommand.ExecuteReader(CommandBehavior
behavior) at MysqL.Data.MysqLClient.MysqLDataReader.ClearKillFlag()
at MysqL.Data.MysqLClient.MysqLDataReader.Close() at
MysqL.Data.MysqLClient.MysqLDataReader.dispose(Boolean disposing)
at MysqL.Data.MysqLClient.MysqLDataReader.dispose() at
Dapper.sqlMapper.d__1361.<>m__Finally1() at
Dapper.sqlMapper.<QueryImpl>d__136
1.MoveNext()

解决方法

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

using (var conn = DataFactory.InitializeConnection(false))
    {
        conn.Execute("ProcedureName",commandType: System.Data.CommandType.StoredProcedure);
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐