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?