c# - MySql.Data.MySqlClient.MySqlException (0x80004005) : SELECT command denied to user 'XXX' @'YYY' for table 'bogus_table'

标签 c# mysql dapper

我正在使用 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__1361.MoveNext()

最佳答案

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

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

关于c# - MySql.Data.MySqlClient.MySqlException (0x80004005) : SELECT command denied to user 'XXX' @'YYY' for table 'bogus_table' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50407365/

相关文章:

c# - Entity Framework ,返回日期错误

c# - 如何将事件处理程序委托(delegate)转换为具有不同签名的委托(delegate)

c# - 在 View 中放置样式标签

mysql - SQL JOIN 查询 - 链接四个表

c# - 与 Dapper 并行执行多个查询

c# - 导入以分号分隔的 CSV 文件

mysql - 使用嵌套查询获取两个表的详细信息

javascript - 基本动态选择列表 PHP 和 AJAX Jquery

dapper.net 核心中的 MySQL 空间数据类型

c# - 将 Dapper.net 与 MySql 和 Oracle 结合使用