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", new
        {
            puserid = ID
        }, commandType: System.Data.CommandType.StoredProcedure);
    }
点赞