Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > ORM Profiler Section > Bugs & Issues> Unable to cast object of type 'SD.Tools.OrmProfiler.Interceptor.ProfilerDbConnection' to type 'System.Data.SqlClient.SqlConnection'.
 

Pages: 1
Bugs & Issues
Unable to cast object of type 'SD.Tools.OrmProfiler.Interceptor.ProfilerDbConnection' to type 'System.Data.SqlClient.SqlConnection'.
Page:1/1 

  Print all messages in this thread  
Poster Message
ptools
User



Location:

Joined on:
06-Jan-2014 16:47:37
Posted:
9 posts
# Posted on: 06-Mar-2014 19:00:16.  
Hi,
after adding the SD.Tools.OrmProfiler.Interceptor.dll as reference to a project

we are getting

Unable to cast object of type 'SD.Tools.OrmProfiler.Interceptor.ProfilerDbConnection' to type 'System.Data.SqlClient.SqlConnection'.

at pTools.CMS.DAL.HelperClasses.DbUtils.CallRetrievalStoredProcedure(String storedProcedureToCall, SqlParameter[] parameters, DataTable tableToFill, ITransaction transactionToUse)
at pTools.CMS.DAL.StoredProcedureCallerClasses.RetrievalProcedures.Stats_GetSingleUserLoginTimes(DateTime fROM_DATE, DateTime tO_DATE, Int32 user_ID)

so it seems that it is inside the generated DAL classes when calling stored procedure

Any idea how to fix that?
we are using llblgen 2.6.0.0

Thanks Petr
  Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
612 posts
# Posted on: 07-Mar-2014 09:37:26.  
You did setup the profiling for llblgen pro v2.6 like described in the docs? It should work, though technically the profiler is designed to work with llblgen pro v3.x and higher.

Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
ptools
User



Location:

Joined on:
06-Jan-2014 16:47:37
Posted:
9 posts
# Posted on: 11-Mar-2014 14:14:11.  
Yes, we setup everything and it actually works, the profiler is showing the DB activity.

But when the application code calls
at pTools.CMS.DAL.HelperClasses.DbUtils.CallRetrievalStoredProcedure(String storedProcedureToCall, SqlParameter[] parameters, DataTable tableToFill, ITransaction transactionToUse)

it seems to somehow use 'SD.Tools.OrmProfiler.Interceptor.ProfilerDbConnection'
instead of type 'System.Data.SqlClient.SqlConnection'.

We have another place where similar error happens:

            DbCommand cmd = CreateCommand(commandText, cn, parameters);
            return cmd.ExecuteScalar();

is throwing an error


[SqlException (0x80131904): Incorrect syntax near '?'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +388
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +688
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4403
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +82
System.Data.SqlClient.SqlDataReader.get_MetaData() +135
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6665229
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) +6667096
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +577
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +107
System.Data.SqlClient.SqlCommand.ExecuteScalar() +270
SD.Tools.OrmProfiler.Interceptor.ProfilerDbCommand.ExecuteScalar() +383
aspnetforum.Utils.DB.ExecuteScalar(DbConnection cn, String commandText, Object[] parameters) +166

  Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
612 posts
# Posted on: 11-Mar-2014 16:27:40.  
I think this is an incompatibility in v2.6. I have to confirm this with the code but I'm fairly certain. We added dbproviderfactory usage in the DQE in v2.6 for sql server so for generated queries this works fine, but the rest is hardcoded still. Perhaps there's a workaround, will check...

The other error looks like it might use sqlCE instead of sqlserver sql generation (sqlserver compatibility mode controls this), if you enable dqe tracing, does it reveal anything in the query? Looks like the parameters are replaced with '?' which was necessary for early versions of sqlce...


Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
ptools
User



Location:

Joined on:
06-Jan-2014 16:47:37
Posted:
9 posts
# Posted on: 11-Mar-2014 16:49:24.  
The second issue - the code is not supposed to use the DAL.
The application is mixture of two parts. One uses llblgen DAL, the other direct DB access.

Basically the DbCommand in the line below should not use llblgen at all

System.Data.Common.DbCommand cmd = CreateCommand(commandText, cn, parameters);

  Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
612 posts
# Posted on: 11-Mar-2014 16:55:23.  
ptools wrote:
The second issue - the code is not supposed to use the DAL.
The application is mixture of two parts. One uses llblgen DAL, the other direct DB access.

Basically the DbCommand in the line below should not use llblgen at all

System.Data.Common.DbCommand cmd = CreateCommand(commandText, cn, parameters);


I am lost here, if that's not our code, what is CreateCommand?

Anyway, the stored proc calls are not supported for teh profiler on llblgen pro v2.6, you need a higher version for that, as the proc calls have hardcoded sqlclient code, so you can't use the profiler for the proc calls on v2.6.


Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
ptools
User



Location:

Joined on:
06-Jan-2014 16:47:37
Posted:
9 posts
# Posted on: 11-Mar-2014 18:14:15. Goto attachments  
It is code from http://www.jitbit.com/asp-net-forum/
That is the second part of the application which I mentioned. Our custom app which uses LLblgen has integrated the forum as part of the same IIS site. Since we added the profiler code to our app, the aspnetform throws that error. You are right with replacing the "?", I see some code like
Code:

            bool sqlDriver = (cmd is SqlCommand);
            if (sqlDriver)
            {
                newCmd = newCmd.Replace("?Param", "@Param");


So it seems that the profiler changes the type from
System.Data.Common.DbCommand
to
SD.Tools.OrmProfiler.Interceptor.ProfilerDbCommand

so the bottom line is that the profiler probably can not be used for such scenario.
  Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
612 posts
# Posted on: 11-Mar-2014 18:42:11.  
Yes the command is a ProfilerDbCommand which wraps the SqlCommand internally. It has the same interface so code which isn't hardcoded to SqlClient and thus uses DbCommand and not SqlCommand, will work normally and doesn't know what type the Command is. Code which does require SqlCommand (and SqlConnection) instances won't work as the command isn't of that type.

Not sure whether you can alter the forum code or not, if not, then indeed it can't be used in that scenario...


Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
fpdave100
User



Location:

Joined on:
28-Jul-2014 13:35:25
Posted:
1 posts
# Posted on: 28-Jul-2014 13:39:52.  
we have a mixture of EF6 code fopr which I need to use the profiler and some older object context based EF code.

I get the invalidcastexception as mentioned above.

Is there any way of disabling it for specific connection strings, or some other criteria, so it can be used even when there is bad code in the solution?Angry
  Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
612 posts
# Posted on: 28-Jul-2014 17:30:59.  
fpdave100 wrote:
we have a mixture of EF6 code fopr which I need to use the profiler and some older object context based EF code.

I get the invalidcastexception as mentioned above.

The older EF code should still work as well. It can be the interceptor isn't called as the first statement in the application, which will make EF not work properly as it then has already cached the factory.

Quote:

Is there any way of disabling it for specific connection strings, or some other criteria, so it can be used even when there is bad code in the solution?Angry

No, it overwrites the factory table in any case. The exception you're seeing is caused by that: some code uses the factory in the table after it has been overwritten (so it will produce wrapped elements) and other code will use a cached factory from before it was overwritten (and thus will cause a problem). the other cause of this exception can be that the framework used has hardcoded cast to SqlClient, however with EF that's not the case after EF 4.0 if I'm not mistaken.


Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.09082011 Final.