PetaPoco.Glimpse – NuGet Package

A couple of weeks ago I showed how we can use the awesome Glimpse project with PetaPoco to show all the SQL’s processed in the current request. The problem was there was a few things that needed to make it into both PetaPoco and Glimpse to support this. The PetaPoco changes were in place as of v3.0.2 (thanks Brad) and a bug fix I submitted to the Glimpse team was just merged into (thanks Nik and Anthony) v0.82.

Therefore I give you PetaPoco.Glimpse. A simple NuGet package that brings it all together. Firstly create a new Asp.Net MVC 3 Project. Right click on References and select “Add Library Package Reference”. The following dialog will appear. Search for petapoco in the top right corner. It will look similar to below. Select PetaPoco.Glimpse and select Install. This will install PetaPoco.Core as well as Glimpse.

PetaPoco.Glimpse

Once it downloads the package and installs it you are almost ready to go. Here is the simplest way to get under way, however usually you would create your own DB class which inherits DatabaseWithProfiling.

// "Peta" is the name of my connection string
var db = new DatabaseWithProfiling("Peta");
var data = db.Fetch<dynamic>("select id, name from users where id = @0", 1);

Placed the above code into the HomeController and run the application. Note: You will also have to turn Glimpse On by heading to /Glimpse/Config. Once done, head back to the default url and you see an Eye icon in the bottom right corner. Clicking this will result it the following output.

PetaPoco.Glimpse1

As you can see, the PetaPoco tab shows you all the details about the SQL’s that were run in the order they were run.

There are a few caveats on the SQL’s showing up.

1. Debug must be on.

2. You can force the logging by setting –> db.ForceLogging = true;

Please let me know if you have any queries and enjoy.

Adam

5 Responses to PetaPoco.Glimpse – NuGet Package

  1. Gareth Elms says:

    Excellent, I had a go at this but my object wasn’t rendered and ‘coz it’s not 1.0 I just left it. Will download tonight should be very useful

  2. [...] used the Glimpse PetaPoco plugin by Schotime (Adam Schroder). Because the Glimpse plugin uses HttpContext.Current.Items all the SQL statements are lost when [...]

  3. Gareth Elms says:

    Hi I noticed that after a response redirect the HttpContext Items is cleared meaning that all SQL statements before the redirect are not available to Glimpse. I made a change using TempData to get around this. It’s described at http://www.garethelms.org/2011/06/petapoco-a-simple-web-app/ do you want me to add it somehow? I can’t find code on GitHub for your Glimpse plugin

  4. Jose Diaz says:

    Why does PetaPoco.Glimpse require and install older version of PetaPoco.Core (3.0.2)?

  5. Schotime says:

    It requires a minimum of 3.0.2. You should be able to update the PetaPoco.Core after that.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>