Quantcast
Channel: Diagnostics – SharePoint Dragons
Viewing all articles
Browse latest Browse all 7

Using the entity framework to see the contents of the SharePoint logging database

$
0
0

In this post, we will discuss how to use entity framework 4.0 to make it really easy to take a look at the contents of the SharePoint logging database. As an example, we’ll look at the performance counters stored in them. To get everything set up and running and to see what we’re going to accomplish, first read:

https://sharepointdragons.com/2011/11/16/leveraging-the-logging-database-to-see-performance-counters/

As you’ve learned from the aforementioned post, we’re going to use the PerformanceCounter view (which combines data from the tables PerformanceCounters_Partition0 to PerformanceCounters_Partition31, each table representing a different day with a total history of 32 days) in combination with the PerformanceCountersDefinitions table to inspect the performance counters. The PerformanceCountersDefinitions table doesn’t have a primary key which, in this case, makes it impossible for the Entity Framework to add it to an Entity Data Model.

Since the WSS logging database is intended for direct use (as opposed to the SharePoint config and content databases), we’ve taken the liberty to promote the Id column in the PerformanceCountersDefinitions table to a primary key. By default, saving this change won’t be supported by the SQL Server designer, so first you have to make a change:

http://www.bidn.com/blogs/BrianKnight/ssis/52/sql-server-2008-designer-behavior-change-saving-changes-not-permitted-1

Now, in VS 2010, create a new class library (name it WSS.Logging.Model, or something) and do the following:

  1. Add > New Item.
  2. Choose ADO.NET Entity Data Model.
  3. Click Add.
  4. Choose Generate from database.
  5. Click Next.
  6. Make a connection to the WSS logging database (for us, its name is WSS_Logging).
  7. Click Next.
  8. Select the PerformanceCountersDefinitions table and the PerformanceCounter view.
  9. Click Finish.
  10. Create a new client (for example, a Windows application).
  11. Add a project reference to the WSS.Logging.Model class library.
  12. Copy the <connectionStrings> section from the WSS.Logging.Model class library and add it to the config file of your client app.
  13. Import the WSS.Logging.Model namespace in the client app and add the following code to the Main() method:

using (WSS_LoggingEntities1 ctx = new WSS_LoggingEntities1())
{
  var counters = from p in ctx.PerformanceCounters
  join d in ctx.PerformanceCountersDefinitions on p.CounterId equals d.Id
  select new
  {
    p.LogTime,
    p.MachineName,
    p.Value,
    d.Counter,
    d.Category,
    d.Instance
  };
grd.DataSource = counters;


Viewing all articles
Browse latest Browse all 7

Trending Articles