0

We have an .net enterprise application which backs onto an SQL Server backend.

With some of our bigger customers now we are coming across some SQL based performance bottlenecks. We've applied as much global indexing that we can see which would increase performance but we are constantly getting customers that push the boundaries past what we would have ever passed as our max use cases and there is nothing to say this is wrong.

What this means though is being able to provide the ability to look at how the bigger customers and provide indexes for their databases. At this point I can only see this achievable in a case by case basis (because all customers will use the system differently).

My thought is to somehow run the SQL Profiler on the customers database for a certain period of time and than pump this data into a table in the database and after that period analyze the data and apply indexes where needed to improve performance.

The enterpise app is asp.net mvc. Does anyone know if we can add .net code that will fire up the SQL profiler from the asp server via a connection string to the database and server and than pump the results into a table?

Or any advice on other approaches we could take?

4 Answers 4

2
+100

SQL Server Profiler is only a graphical interface to show all the events handled by SQL Trace API. It is possible to start and capture trace data through SQL stored procedures and .Net code. Here is two examples on how to do it. It isa bit old, but I have managed to start sql trace throm .net code following the instructions.

http://blogs.msdn.com/b/sqlprogrammability/archive/2006/05/26/receiving-profiler-events.aspx

Here is a list of stored procedures that are executed by the profiler to start the trace. You can allways run them directly. http://technet.microsoft.com/en-us/library/ms187346.aspx

1

As mentioned by user907246, SQL Profiler is only graphical interface to show the trace information collected by SQL Server Trace API, allowing to get and analyze the data online. But SQL Profiler makes a huge overload on the server and not recommended to be started in the Production environment.

Instead of the Profiler the Server-side trace can be configured and used as described here (http://technet.microsoft.com/en-us/library/cc293613.aspx). You can specify the trace files sizes, files roll-up, trace filters and other important criterias. Using of server trace instead of SQL Porfiler can reduce the server load and will allow to gather the same information to the offload analyzing: the huge amount of tools can be used for the offline trace analysys, ex. QURE ANALYZER from DBSofic - free product designed for the offline trace analysis with ability to group and filter data by different dimensions and find the performance bottlenecks.

Among this, the extended event were added in the SQL Server 2008 (http://technet.microsoft.com/en-us/library/bb630354(v=sql.105).aspx) which will replace the SQL trace in the future versions. Additional information about configuring and using Extended Events can be found here: http://blogs.msdn.com/b/extended_events/

0

I wouldn't recommend programmatically starting a trace because of the overhead.

Instead, a much lower overhead way to get near-trace-quality data from SQL Server is the plan cache (aka the procedure cache). Whenever you pass a SQL statement into SQL Server (even as a stored proc), SQL Server has to build an execution plan for that statement. It caches the plans in memory to avoid building them over and over, and it tracks the usage of each plan. You get information about the number of times it's called, how much CPU time & duration it runs up, how many logical reads it does, and more.

You can start with our standalone plan cache query: http://www.brentozar.com/responder/get-top-resource-consuming-queries/ Sort by logical reads descending if you want to see which queries are reading the most data - those are often the best candidates for indexing.

And if you wanna go even further, check out my free sp_AskBrent®. It's a stored procedure that takes a sample of the plan cache (plus Perfmon counters, storage metrics, and more), waits 5 seconds, takes another sample, and then compares the differences. The results tell you why the SQL Server is slow right now.

-1

What you are describing is the purpose behind SQL Server's Database Engine Tuning Advisor. Run a trace with SQL Server Profiler, then use that for input into the Database Engine Tuning Advisor. If you are truly having bottlenecks due to SQL, then it will tell you. Otherwise you will have to start looking at memory utilisation, disk IO, CPU %, etc...on both database and application OSs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.