使用MVC-迷你分析器 [英] Using mvc-mini-profiler

查看:128
本文介绍了使用MVC-迷你分析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用MVC-迷你探查与EF codeFirst我创建一个DbProfiledConnection,并把它传递给的DbContext建设如下。该应用程序将继续由SQL无法按预期暴露在探查工作。

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)
    {   

    }

哎呀我的坏。

我修改它,这样,当我在WebContext我的UnitOfWork构建我在ProfiledDbConnection通

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);
}

我检查和MiniProfier目前已被的Application_BeginRequest设置并返回一个ProfiledDbConnection当我再试着查询错误在ProfiledDbProviderServices类抛出的数据库。

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);
 }

此方法返回一个的提供者未返回ProviderManifestToken字符串。误差

this method returns a "The provider did not return a ProviderManifestToken string." error

推荐答案

我的犯罪嫌疑人的这涉及到静态字段初始化。在Web应用程序的连接应的从不的是静态的呢(但要求特定的最多)。

I suspect this relates to the static field initializer. Connections on web apps should never be static anyway (but request-specific at most).

最关键的是:是什么 ProfiledDbConnection 居然出来的?在获取方法返回一个 ProfiledDbConnection 只有当你正在分析(在当前请求),以及连接异形反对该请求的 MiniProfiler 实例。

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 为空

  • 静态字段被初始化,但一切都记录针对第一个请求,这是快死

  • the static field is initialized without a request context (or a non-developer request context): no profiling will occur as MiniProfiler.Current is null
  • the static field is initialized, but everything is logged against the very first request, which is quickly dead

这篇关于使用MVC-迷你分析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆