If the command is too long to view in the grid, we can double-click the message cell and see the message in a dialog.

Using TraceViewer Information to Resolve Problems
Suppose our application displays a grid with hundreds of Employees. Each grid row includes a digest of an employee's orders - the number of orders, the customers, the total dollar values, etc.
If we code the grid in a naive way, with no attention to performance, we will see a flurry of entries in the TraceViewer. Every time the user scrolls from one employee grid line to the next, we see a new flurry. The messages will really fly if the user clicks a column header to sort the grid.
We scroll back through the messages and see the problem. DevForce is making a lot of little trips to the database. There is a trip for each employee's orders. There's another trip for each employee order's customer. There's another trip for each employee order's item details. No wonder the application is a dog.
There was nothing wrong with our original naive implementation per se. Our first goal should be to make the application work using the simplest approach necessary. We accomplished that goal. We were not going to anticipate a performance problem before we had a performance problem.
Now that we have performance problem, the TraceViewer helps us identify it quickly so we can fix it.
Fortunately, the fix is easy: we add spans to the query so that DevForce makes a single request to fetch all of the employee, order, customer, and item detail data that we know we're going to display in the grid. Problem solved.
Note:
Span queries are a topic for another Tech Tip. You can read about them in our Developers' Guide.
Add the TraceViewer to Your Program
It's incredibly easy to do.
1. In your start-up project, add a reference to IdeaBlade.UI.WinForms.PlatformControls.
2. Open your start-up class (typically Program.cs or Program.vb).
3. Find the static Main method (Shared Main in VB).
4. Make some room just below any calls to the Application class (e.g., Application.EnableVisualStyles()).
5. Add the following code to show the TraceViewer.
// C#:
IdeaBlade.UI.WinForms.PlatformControls.TraceViewerForm traceForm;
traceForm = new IdeaBlade.UI.WinForms.PlatformControls.TraceViewerForm();
traceForm.Show();
' VB.NET:
Dim traceForm As _
New IdeaBlade.UI.WinForms.PlatformControls.TraceViewerForm()
traceForm.Show()
That is all there is to it. Next time you launch your application, the TraceViewer will appear, followed shortly thereafter by your application's main window. You can toggle between the two windows at will.
Why Don't I Just Use SQL Profiler?
Use SQL Profiler by all means. It's a fantastic tool for monitoring database activity dynamically in much the same was as you use the TraceViewer.
You still want to launch the TraceViewer for a number of reasons, including:
- Your application launches the TraceViewer for you; you have to remember to launch the SQL Profiler.
- The SQL Profiler only tells you about database activity; the TraceViewer captures other application activity in addition to database activity.
- You can customize the messages in the TraceViewer so you can see what part of your application results in a specific database request.
Conclusion
The TraceViewer is a critical development tool that's easy to run. I add the TraceViewer to my application within the first five minutes of coding. It's a great habit to get into; make it one of yours.
Notes:
· The TraceViewer runs in the same process as your application. You can run it in a separate process if you prefer. It takes a tiny bit more work; see the Developers' Guide for more information.
· You can close the TraceViewer without shutting down your application.
· I don't want my customer to see the TraceViewer. I wrap those launch lines in compiler debug directives so the TraceViewer never shows in release mode.
· N-tier deployment results in a slightly different approach to logging. The Developers' Guide can tell you more.