Get SQL Stats in ASP.NET

2. May 2008

Hey everyone I wanted to post some code I had sometime back when on how I pulled SQL stats from a SQL Server using VB.NET and ASP.NET.  The code that will be in this post is actually part of a class that handles the SQL stats, but you can incorporate it however you would like.  There are a few things required for this. 

1. This is written in .NET 2.0
2. You need to add Imports System.Diagnostics   to your class or aspx page
3. You also have to have the rights to pull system stats from your SQL Server.  What this means is that you either need to enable Indentity Impersonate on the web application and make sure whoever uses the app has rights, or run the web application under an Application Pool in IIS that has access to the SQL Servers.
4. You'll see a variable in this class Me._Server.  Replace this with the server name you are trying to pull stats from or create a variable names _Server as a String
5. Add a reference to the COM object Microsoft SQLDMO Object Library 

Ok so here is some code that should get you by for a simple SQL Monitoring tool.  Again you can use this wherever you want in your app.  I had mine in a seperate class.

Again hope this helps those that need to gather sql stats in a quick manner or need to monitor a sql server for stat purposes / high overview of usage. 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

ASP.NET, Microsoft SQL ,

Comments

5/2/2008 7:08:05 PM #
Trackback from DotNetKicks.com

Get SQL Stats in ASP.NET
Malar
9/12/2008 1:40:35 PM #
Hey John,
   Great job...it is really helpful to me...thanx a lot..
John_M
9/13/2008 1:40:53 AM #
No problem Malar, I found it useful myself for quick stats.

John M (author)
Malar
9/24/2008 8:36:59 AM #
Hai john,

   I want to know that,whether it is possible only in ASP or  can we do this(getting stats of SQL) in C++/java also?..if it is possible means what steps should i follow.?i gone through lots of blogs..but still am not clear..plzz let me know..

thanks in advance..
John_M
9/25/2008 10:10:32 PM #
Malar,

If you are using C++ managed in .NET then you should be able to.  Just make sure you reference System.Diagnostics.  As far as Java or just C++ you may be able to pull stats via SNMP. Let us know how it goes.

John M(author)
Malar
9/26/2008 2:47:52 PM #
Hello John,
    
     Happy to receive ur reply...

     If once I done using C++ managed in .NET, then the target machine(which am going to monitor) also should have .NET environment..right?
..or is it enough to register required dll in target machine?

Do u have any link for java/C++ + SNMP?

Thanks in Advance...John



    

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading