Search code examples
c#mysqlmysql-connectormvc-mini-profiler

How to use mvc-mini-profiler with mysql connection?


I'm currently trying to use the mvc-mini-profiler with a MySQL Connection. Is there a way to do this with some kind of custom wrapper?

var mysqlConn = new MySqlConnection("Data Source=localhost; ...");
string commandText = "SELECT ...";

ProfiledDbConnection profiledConn = new ProfiledDbConnection(mysqlConn, MiniProfiler.Current);           

var sqlCom = new MySqlCommand(commandText, profiledConn); // error, expects MySQLConnection, not DBConnection

thanks!


Solution

  • Use:

    var sqlCom = profiledConn.CreateCommand(); 
    sqlCom.CommandText = commandText; 
    

    It is critical the commands are intercepted for the profiling to work.