我使用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命令 拒绝用户' XXX' @' YYY'表格' 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 强制)在MySql.Data.MySqlClient.MySqlDataReader.NextResult()at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(的CommandBehavior 行为)在MySql.Data.MySqlClient.MySqlDataReader.ClearKillFlag() 在MySql.Data.MySqlClient.MySqlDataReader.Close()处 MySql.Data.MySqlClient.MySqlDataReader.Dispose(布尔处理)
在MySql.Data.MySqlClient.MySqlDataReader.Dispose()处 Dapper.SqlMapper.d__1361.<>m__Finally1() at Dapper.SqlMapper.<QueryImpl>d__136
1.MoveNext()
答案 0 :(得分:1)
这可能是Mysql Driver实施中的问题;这是提及bogus_table的代码块。 如果您的过程有空结果,请尝试使用Execute 调用(因为它实现了内部执行非查询)而不是Query。
using (var conn = DataFactory.InitializeConnection(false))
{
conn.Execute("ProcedureName", new
{
puserid = ID
}, commandType: System.Data.CommandType.StoredProcedure);
}