Skip to main content

Posts

Showing posts from December, 2008

Writting a SQL Profiler

In case you're wondering how to write a SQL Profiler to automate some of your task, here are some code that you might want to try out :)


Add reference to Microsoft.SqlServer.ConnectionInfo in your project and you are good to go!


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SqlServer.Management.Trace;
using Microsoft.SqlServer.Management.Common;

using System.IO;
using System.Configuration;

namespace MSSQLProfiler
{

public class MSSqlTracer
{

ConnectionInfoBase conninfo = null;

public string TemplateTraceFile { get; set; }
public string TraceOutputFile { get; set; }


public void StartTrace(string TemplateFileSource, string OutputFileName)
{

TemplateTraceFile = TemplateFileSource;
TraceOutputFile = OutputFileName;

Initialization();

/// Perform Database Tracing ////

RunTracing();


}

private void RunTracing()
{

Trace…