MvcMiniProfiler 2 and LLBLGen Pro 3.5 Adapter Stored Procedures

Posts   
 
    
trancehead
User
Posts: 137
Joined: 03-Dec-2007
# Posted on: 14-Feb-2013 08:31:28   

Whenever a stored procedure is called with a profiled DataAdapater I get the following error: Unable to cast object of type 'StackExchange.Profiling.Data.ProfiledDbConnection' to type 'System.Data.SqlClient.SqlConnection'.

Here is the ProfiledDbConnection class:


    public class ProfilingDynamicQueryEngine : DynamicQueryEngine
    {
        /// <summary>
        /// Creates the command.
        /// </summary>
        /// <returns></returns>
        protected override DbCommand CreateCommand()
        {
            var cmd = base.CreateCommand();
            var pCmd = new ProfiledDbCommand(cmd, null, MiniProfiler.Current); 
            return pCmd;
        }
    }

    public class ProfiledDataAccessAdapter : DataAccessAdapter
    {
        public ProfiledDataAccessAdapter(string connectionString)
            : base(connectionString, false)
        {
        }

        /// <summary>
        /// Creates a new physical connection object.
        /// </summary>
        /// <param name="connectionString">Connectionstring to use for the new connection object</param>
        /// <returns>
        /// DbConnection implementing connection object.
        /// </returns>
        protected override DbConnection CreateNewPhysicalConnection(string connectionString)
        {
            var conn = base.CreateNewPhysicalConnection(connectionString);
            return new ProfiledDbConnection(conn, MiniProfiler.Current);
        }

        /// <summary>
        /// Creates a new Dynamic Query engine object and passes in the defined catalog/schema overwrite hashtables.
        /// </summary>
        /// <returns></returns>
        protected override DynamicQueryEngineBase CreateDynamicQueryEngine()
        {
            return new ProfilingDynamicQueryEngine();
        }

    }

Is there a way to solve this?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 14-Feb-2013 09:58:53   

and where do you get this exception, stacktrace etc. ?

Frans Bouma | Lead developer LLBLGen Pro
trancehead
User
Posts: 137
Joined: 03-Dec-2007
# Posted on: 14-Feb-2013 11:38:29   

Stack trace

System.InvalidCastException: Unable to cast object of type 'StackExchange.Profiling.Data.ProfiledDbConnection' to type 'System.Data.SqlClient.SqlConnection'.
   at Paysoft.Secure.Data.DatabaseSpecific.DataAccessAdapter.CallActionStoredProcedure(String storedProcedureToCall, SqlParameter[] parameters) 

The exception is thrown on line 9 below:


1.               /// <summary>Calls stored procedure 'UpdateBatchRejectedCounts'.      </summary>
2.      /// <param name="dataAccessProvider">The data access provider.</param>
3.      /// <param name="transactionId">Input parameter. </param>
4.      /// <returns>Number of rows affected, if the database / routine doesn't suppress rowcounting.</returns>
5.      public static int UpdateBatchRejectedCounts(System.Int64 transactionId, IDataAccessCore dataAccessProvider)
6.      {
7.          using(StoredProcedureCall call = CreateUpdateBatchRejectedCountsCall(dataAccessProvider, transactionId))
8.          {
9.              int toReturn = call.Call(); <-- Exception thrown here
10.             return toReturn;
11.         }
12.     }

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 14-Feb-2013 16:55:45   
at Paysoft.Secure.Data.DatabaseSpecific.DataAccessAdapter.CallActionStoredProcedure(String storedProcedureToCall, SqlParameter[] parameters) 

that's not our code. The stacktrace is also incomplete. Please check that method above and whether you're doing anything SqlClient there (I think you do, considering the SqlParameter type in the signature)

The generated code doesn't have any ADO.NET specific types anymore.

Frans Bouma | Lead developer LLBLGen Pro
trancehead
User
Posts: 137
Joined: 03-Dec-2007
# Posted on: 15-Feb-2013 06:29:52   

I've had to revert the code but when I implement it again, I'll try and get the full stack trace.