gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 07:38:26 24 4
gpt4 key购买 nike

我正在使用 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);
}

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com