I'm using Dapper for calling MySql stored procedure. The procedure executes just fine, but after that the code throws an exception. The code block that is problematic is like this:
using (var conn = DataFactory.InitializeConnection(false))
{
conn.Query("ProcedureName", new
{
puserid = ID
}, commandType: System.Data.CommandType.StoredProcedure);
}
Where DataFactory
is the following static class:
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");
}
}
I have no bogus_table
in my database, tho it is shown in the error message:
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()
it's maybe problem in Mysql Driver implementation; here is code block that mentions bogus_table. if your procedure has empty result try to call with Execute (because it implements execute non query inside) instead of Query.
using (var conn = DataFactory.InitializeConnection(false))
{
conn.Execute("ProcedureName", new
{
puserid = ID
}, commandType: System.Data.CommandType.StoredProcedure);
}