I'm trying to use the mvc-mini-profiler with EFCodeFirst I'm creating a DbProfiledConnection and passing it to the DbContext on construction as below. The application continues to work as expected by the sql is not exposed to the Profiler.
public class WebContext : DbContext
{
static DbConnection _connection = new SqlConnection(ConfigurationManager.ConnectionStrings["WebContext"].ConnectionString);
static DbConnection _profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(_connection);
public WebContext()
: base(_profiledConnection, true)
{
}
oops my bad.
I've modified it so that when my WebContext is constructed in my UnitOfWork i pass in a ProfiledDbConnection
public UnitOfWork()
{
var profiledConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(connection);
this.context = new MyContext(profiledConnection);
}
I've checked and MiniProfier Current has been set in Application_BeginRequest and it returns a ProfiledDbConnection when I then try and query the database an error is thrown in the ProfiledDbProviderServices class.
protected override string GetDbProviderManifestToken(DbConnection connection)
{
return tail.GetProviderManifestToken(connection);
}
this method returns a "The provider did not return a ProviderManifestToken string." error
MiniProfiler is a library and UI for profiling your application. By letting you see where your time is spent, which queries are run, and any other custom timings you want to add, MiniProfiler helps you debug issues and optimize performance.
Persisting profiling dataAdd the reference “MiniProfiler. Providers. SQLServer” package and add following code in AddMiniProfiler method. Miniprofiler database will not be autogenerated so you need to create using script before running the application.
MiniProfiler is a library and UI for profiling your application. MiniProfiler helps you to measure perfomance of your applications. With Entity Framework extension you will be able to measure query performance.” First you need to install the MiniProfiler package and MiniProfiler Entity Framework package.
I suspect this relates to the static field initializer. Connections on web apps should never be static anyway (but request-specific at most).
The key is: what does ProfiledDbConnection
actually come out as? The Get
method returns a ProfiledDbConnection
only if you are currently profiling (on the current request), and the connection is profiled against the MiniProfiler
instance on that request.
If you use a static field, then there are two scenarios:
MiniProfiler.Current
is nullIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With