Search code examples
c#oracle-databasedatabase-connectionmvc-mini-profilerdbconnection

MvcMiniProfiler not working with Oracle's Connection Object


the last line of the following code triggers an exception: OracleConnection conn = new OracleConnection(getConnectionString());

        // A SqlConnection, SqliteConnection ... or whatever          
        // wrap the connection with a profiling connection that tracks timings      
        var cnn = MvcMiniProfiler.Data.ProfiledDbConnection.Get(conn, MiniProfiler.Current); 
        OracleCommand cmd = new OracleCommand(sql, (OracleConnection) cnn);

Which is:

Unable to cast object of type 'MvcMiniProfiler.Data.ProfiledDbConnection' to type 'Oracle.DataAccess.Client.OracleConnection'.

I'm using Oracle Data Provider. THe same happens with devArt for oracle.

Thanks :)


Solution

  • That is because you need to treat it as an abstract connection, and use the existing CreateCommand, CreateParameter etc methods on the base class/interface. Or if you want to avoid that confusion - something like "dapper" (or any other ADO.NET utility layer) will save you much pain.

    The reason here is that profiler "decorates" the connection, which in turn means it must decorate the other objects and unwrap them at the correct times. That is indeed how it is possible to profile ADO.NET in this way