mishrsud / mvc-mini-profiler

Automatically exported from code.google.com/p/mvc-mini-profiler
0 stars 0 forks source link

Unable to cast object of type 'MvcMiniProfiler.Data.ProfiledDbConnection' to type 'System.Data.SqlClient.SqlConnection' #29

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Trying to use profiler for SQL as described at docs:

MvcMiniProfiler.Data.ProfiledDbConnection.Get(cnn, MiniProfiler.Current);

I'm working with DbProviderFactory directly without EF or LINQ-2-SQL.

Original issue reported on code.google.com by zubkov.p...@gmail.com on 20 Jun 2011 at 10:17

GoogleCodeExporter commented 8 years ago
Yeah, would be nice to have SqlConnection supported for profiling...

Original comment by marko.vn...@gmail.com on 22 Jun 2011 at 4:32

GoogleCodeExporter commented 8 years ago
Even when used correctly, this is also an issue with NHibernate and batching, 
as it casts the ProfiledDbCommand to SqlCommand.
(see issue and workarounds: 
http://stackoverflow.com/questions/6374081/using-mvc-mini-profiler-database-prof
iling-with-nhibernate)

Original comment by kellystu...@gmail.com on 27 Jun 2011 at 6:41

GoogleCodeExporter commented 8 years ago
Perhaps the use of a RealProxy (as DbCommand is MarshalByRefObject) would help 
out.

Creating proxies with RealProxy:
http://www.neovolve.com/post/2010/07/17/Creating-proxies-with-RealProxy.aspx
Using a Custom Proxy For Interception:
http://blogs.msdn.com/b/geoffda/archive/2007/11/07/using-a-custom-proxy-for-inte
rception.aspx

Original comment by kellystu...@gmail.com on 27 Jun 2011 at 6:43

GoogleCodeExporter commented 8 years ago
Nevermind. That opens a whole new can of worms. Did it and had issues with 
internal classes accessing internal properties (ObjectId).

Original comment by kellystu...@gmail.com on 5 Jul 2011 at 2:35

GoogleCodeExporter commented 8 years ago
@Kelly I used a RealProxy solution in a previous profiling project and it 
worked quite well, SQLConnection is marshal by ref, so you could proxy all the 
way through.

Can you expand what errors you had? Did you proxy the connection as well and 
then intercept createcommand to return another proxy? 

Original comment by sam.saff...@gmail.com on 10 Jul 2011 at 6:12

GoogleCodeExporter commented 8 years ago

Original comment by jarrod.m.dixon on 11 Jul 2011 at 4:45

GoogleCodeExporter commented 8 years ago
I just opened up the new ProfiledDbProviderFactory you can wrap your factory 
with that if you wish to use it ... it will take care of the reset

let me know if it works for you. 

new ProfiledDbProviderFactory( MiniProfiler.Current, existingFactory);

Original comment by sam.saff...@gmail.com on 12 Jul 2011 at 4:22

GoogleCodeExporter commented 8 years ago
Im assuming this if fixed, let me know if it needs to be reopened

Original comment by sam.saff...@gmail.com on 26 Jul 2011 at 12:34

GoogleCodeExporter commented 8 years ago
I'm sorry, but this does not resolve Unable to cast object of type 
'MvcMiniProfiler.Data.ProfiledDbConnection' to type 
'System.Data.SqlClient.SqlConnection' problem. 

I'm not using any factory so ...

Original comment by marko.vn...@gmail.com on 26 Jul 2011 at 6:54

GoogleCodeExporter commented 8 years ago
If I understand the OP correctly he wants to use SqlConnection instead of 
DbConnection.
Is the issue closed due to the right reason?

I have an interest too in SqlConnection (since I want to avoid rewriting my 
datalayer using SqlConnection (and Dapper)).

Original comment by ola.fjelddahl on 27 Jul 2011 at 2:21

GoogleCodeExporter commented 8 years ago
I also am interested in support for SqlConnection.  I have hundreds and the 
thought of having to re-work them all.......

Original comment by jaytow...@gmail.com on 4 Aug 2011 at 12:50

GoogleCodeExporter commented 8 years ago
This isn't fixed. I need to use SqlConnection instead of DbConnection :/

Original comment by levitiko...@gmail.com on 20 Apr 2015 at 7:05