Home > Articles > Data > SQL Server

Using SQL Profiler to Find Errors

One of the best tools for helping to solve problems in SQL Server 2000 is SQL Profiler. In this chapter excerpt, author Rob Hawthorne tells you how SQL Profiler, as a problem-solving tool, can show you exactly what has been sent to the SQL Server by a client application.
This article is excerpted from the author's book SQL Server 2000 Database Development From Scratch.
This chapter is from the book

One of the best tools for helping to solve problems in SQL Server 2000 is SQL Profiler. SQL Profiler as a problem-solving tool can show you exactly what has been sent to the SQL Server by a client application.

I have had to upgrade a SQL Server from version 6.5 to version 7.0 (yeah, I know it should have been 2000, but the client couldn't wait). The client had an old Visual Basic interface (written by someone else) and no source code available for the client application. I used SQL Profiler to trace the Transact-SQL statements that were sent to the database from the client application to ensure that the upgrade to SQL Server version 7.0 would go smoothly. The tool was invaluable, and allowed the upgrade to go as easily as possible.

Let's take a look at SQL Profiler and see what it has on offer. In this section we will set up a trace to capture the commands that the client application (Spy Net) sends to our SQL Server 2000 application.

Creating the Trace

We will start the trace and capture all (no specific) of the commands that the browser sends to our SQLSpyNet database, including login information and a basic search.


The ability to capture information from the browser as it goes to SQL Server is one of the best forms of debugging that you can do! It is simple yet very effective, so if you are going to do any sort of front-end development, pay close attention.

  1. SQL Profiler can be launched from within Enterprise Manager (under Tools, SQL Server Profiler) or from within the SQL Server menu group in your Start menu, by selecting Programs, Microsoft SQL Server, Profiler.

  2. When you have SQL Profiler launched, the first thing you need to do is set up a trace definition. You can do this by selecting File, New, Trace, as shown in Figure 1 (or use Ctrl+N).

    Figure 1 Launching the new trace definition screen.

    This will prompt you for your login information so that your connection information can be validated against the database on which you want to perform a trace.

  3. Fill in the login information and you will see a screen similar to that shown in Figure 2.

    Figure 2 Setting the properties for the new trace definition.

  4. Next, define the trace. As you can see on this screen, you have several options (and even more on each of the tabs). Fill in the blanks on the General tab as described in the following:

    • Trace Name—Allows you to enter the unique name for your trace to identify the individual traces later on. Enter Trace for Spy Net.

    • Trace SQL Server—Specifies the instance of SQL Server on which you want to perform a trace. Make sure the instance (if you have more than one) that contains SQLSpyNet is selected.

    • Template Name—Allows you to choose from a list of predefined templates that ship with SQL Server 2000. These templates are designed to assist you with the different aspects of a DBA role. For example, a SQLProfilerTuning template will assist you in tuning your SQL queries and database performance. Select the SQLProfilerStandard template.

    • Template File Name—This allows you to choose another template (custom written, for example) that you can use instead of the predefined ones that come with SQL Server 2000. These template files have a .tdf file extension. You do not need to change this option for our needs.

    • Save to File—This, as you can imagine, allows you to save the trace to a file. So if you wanted to implement auditing in your application, you could capture all events against your server/database and save the trace file to disk. You don't need to do this.

    • Save to Table—Alternatively, you can save your trace to a table within your database. This allows you to save the events in either an existing table or in a new table within any databases that you have access to. Like the Save to File option, you do not need to do this.

    • Enable Trace Stop Time—This allows you to specify how long you would like to run a trace. Leave this unchecked for now.


    This is invaluable if we are auditing our application! We can specify the times that we want to trace for, meaning we can capture the peak time traffic or the after-hours potential hacker traffic!

  5. Click the Events tab. As shown in Figure 3, this window allows us to specify the event classes that we want to trace against.

    Figure 3 Setting the events we want to capture for the new trace definition.

    The event classes allow us to capture when an event is prepared, executed, or completed for all the major Transact-SQL categories. We can capture when a stored procedure was started, recompiled, or completed, for example. For our needs though, the defaults of the SQLProfilerStandard template are fine.


    If you save your trace and review the trace properties at a later date, the only events that you will see are the captured events; the Available Event Classes box will be disabled.

  6. Click The Data Columns tab, as shown in Figure 4. This dialog allows us to specify the columns of information that we want to see displayed in our trace.

    Figure 4 Setting the columns we want to see for the new trace definition.

  7. Because we are not on an NT-based system, remove the NTUserName column from the Selected Data select box. Click the NTUserName column, and then click the Remove button.


    If you do not see the NTUserName column, look under the Columns group (written in bold).

  8. To see the last and one of the most-used tabs in the Profile Trace Properties screen, click the Filters tab.

    The Filters tab allows us to apply filters to our traces so that we can narrow our traces to specific databases, users, or even applications.

  9. Because we are only interested in what happens to our SQLSpyNet database (in this instance), find your way to the DatabaseName column, click the plus (+) symbol, and enter SQLSpyNet in the Like box, as shown in Figure 5.

    Figure 5 Setting the filters for the new trace definition.

    This will restrict the filter to show only those events that occur in the SQLSpyNet database.

  10. And that's it! Our trace definition is now ready to go. Click the Run button and the Trace will start.

Sometimes this can take a little while, depending on the speed of your machine and how busy it is processing requests, so be patient.

When the trace starts, it will capture some basic information about the existing connections (if any), so you might notice several entries appear in the window that seem as though they are not relevant to our application.

Am I Already Connected?

What the trace is doing is logging that a connection is already established against the SQL Server. This can show you that users are already connected, so performing a large query could impact them.

If you are seeing that the trace is reporting an existing connection (considering we are in a single-user environment) you probably have Enterprise Manager, Query Analyzer, or Spy Net open, or even a combination of all three.

If you close these applications, stop the trace (by clicking the red square in the toolbar) and clear the trace window by selecting Edit, Clear Trace Window from the menu bar, you will have a fresh trace screen. Now restart the trace (by clicking the green triangle in the toolbar) and voila—no more existing connection information!

Spying on Users

So there we go; our trace is started. How do we check what our users are doing?


Make sure you still have the SQL Profiler window open with the trace running to complete the steps in the following section.

  1. Open the Spy Net application, and enter your login information, then go to the Search screen.

  2. Perform a search. Figure 6 shows that I've performed a search for Greg and an entry is logged in the trace window.

    Figure 6 Spying on our users to see what they are doing.

    This shows that a user (ourselves) has executed the stored procedure PersonSearch with the parameters 'Greg' and NULL.

  3. We can then copy this command and paste it into a Query Analyzer window to see the results that SQL Server 2000 will return for the query.


You can copy the command that was sent to the SQL Server by the client application by clicking the command and then highlighting the text in the Results window. Right-click and select Copy or use the shortcut keys Ctrl+C.

See what I mean about help when you are debugging? If you can see the commands sent to the SQL Server from the client application, you can easily see what parameters are missing or check to see whether they are malformed and so forth. As you can imagine, this becomes very powerful when you continually have an error returned from a client application and you just can't figure it out! Capture the command, submit it to the SQL Server through Query Analyzer, and nine times out of ten, your problem will be resolved.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020