Can MvcMiniProfiler display SQL parameter values?
Asked Answered
K

1

11

I've been trying out MvcMiniProfiler as replacement for EFTracingProvider since it's so much simpler to configure.

It will display the sql just fine, but I'd like to see the parameter values as well.

insert [dbo].[PersonName]([Prefix], [GivenName], [MiddleName], [FamilyName], [Affix])
values (@0, @1, @2, @3, @4)
select [Id]
from [dbo].[PersonName]
where @@ROWCOUNT > 0 and [Id] = scope_identity()

Can MvcMiniProfiler display sql parameter values?

Here's my Global.asax. I'm using EF 4.3.1 with code-first.

protected void Application_Start()
{
    Bootstrapper.Initialize();

    AreaRegistration.RegisterAllAreas();

    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);

    MiniProfilerEF.Initialize();
}

protected void Application_BeginRequest()
{
    if (Request.IsLocal)
    {
        MiniProfiler.Start(ProfileLevel.Verbose);
    }
}

protected void Application_EndRequest()
{
    MiniProfiler.Stop();
}
Karl answered 3/4, 2012 at 14:2 Comment(0)
R
18

If you want the SQL Server Formatter, try adding:

MiniProfiler.Settings.SqlFormatter = 
    new StackExchange.Profiling.SqlFormatters.SqlServerFormatter();

In Application_Start

Richthofen answered 11/4, 2012 at 23:57 Comment(1)
nudoq.org/#!/Packages/MiniProfiler/MiniProfiler/… A couple of notes: 1) It adds the parameters above the sql in a declare statement, which is convenient for copy pasting and running directly in ssms. 2) It seems like you can add the line above in _BeginRequest as well, it doesn't have to be in Application_Start. In my case I wanted to control the formatting with a runtime parameter. NULL it out if you want NO SQL to show or see the documentation for other formatters.Inhabiter

© 2022 - 2024 — McMap. All rights reserved.