1

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 :)

ClayKaboom
  • 1,833
  • 1
  • 22
  • 42

1 Answers1

2

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

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • See also: http://msdn.microsoft.com/en-us/library/system.data.common.dbconnection.createcommand.aspx – Marc Gravell Jul 29 '11 at 19:22
  • Thanks! But is it possible to use the FIll Command? Before MVC MiniProfiler the application was filling a datatable. The base Command Object does not provide the Fill Method, and so far I could not instantiate a proper DataAdapter. If it is not possible I will have to make a huge change transforming datatable(which uses extended properties) into datareaders. – ClayKaboom Aug 01 '11 at 12:08
  • @ClayKaboom OracleCommand *also* doesn't have a `Fill` method AFAIK... If you are using DataTable, then that is the job of either the DataTable or an apapter, no? – Marc Gravell Aug 01 '11 at 12:42
  • No, none of the Command Object have Fill methods, but in the former way I was doing I could instantiate a new OracleDataAdapter. How could I instantiate a Profiled DataAdapter? – ClayKaboom Aug 01 '11 at 12:47
  • @ClayKaboom an excellent question; I am investigating that now. I have the DbProviderFactory, so I can get the CreateDataAdapter - but needs wrapping. Working on it. – Marc Gravell Aug 01 '11 at 13:04
  • @ClayKaboom - I don't have an immediate answer to that (it is going to take a little looking), but it should be possible. It is going to take a little time, however. – Marc Gravell Aug 01 '11 at 13:13
  • No problem, I'm also lookinf after it. I think I should create another question for this issue. – ClayKaboom Aug 01 '11 at 14:13
  • I posted another question here : http://stackoverflow.com/questions/6925314/how-could-i-instantiate-a-profiled-dataadapter-to-use-with-mvc-mini-profiler for whoever wanna track the problems faced. I think many must have done that before, unless theyy are using Entity Framework, which works nice and easy; – ClayKaboom Aug 11 '11 at 10:53