views:

71

answers:

6

Is there a way using sql 2008 Management Studio to look at the queries that hit the server? I'm trying to debug a program and I get messages like "Incorrect syntax near the keyword 'AND'". Since the queries are being dynamically generated it's a hassle to figure out what is going to the server.

Any help is appreciated!

+2  A: 

I'm not aware of any method to do this using SQL Server Management Studio, but if you installed SSMS then you probably also installed the SQL Profiler. If you fire that up and run the TSQL_SPs profiler template, you can see every statement that's hitting the database.

Aaronaught
Honestly, who downvoted this?
Aaronaught
+1  A: 

Go to Management...Activity Monitor in the object explorer.

It's not live though, you will have to refresh it manually.

Neil N
This gives me Recent Expensive queries, but not queries that did not run to completion. Thanks though!
Shaded
+6  A: 

There is a tool called Profiler that will tell you all information that you'll need. MSDN: http://msdn.microsoft.com/en-us/library/ms187929.aspx

Mike M.
This seems to be just what I needed... with a little bit o' learnin'!Thank you!
Shaded
+2  A: 

Since the queries are being dynamically generated it's a hassle to figure out what is going to the server.

Why not just put the query that's generated into a message box, or print it to the console, or webpage, etc. ??

Trying to catch it at the DB server seems to be the long-way-around to debugging some simple ad-hoc queries.

Neil N
It's actually sending the query from a Jasper report, I can print out parts of the query that I'm generating but I can't print out the actual query that is being sent.
Shaded
I see, then I guess the activity monitor would come in handy.
Neil N
A: 

start up profiler from SSMS (Tools-->SQL Server Profiler), run a trace and select the T-SQL events

SQLMenace
A: 

One option is to use SQL Server Profiler to run a trace. However, in some shops SQL Server permissions are set so only DBAs can run traces.

If you don't have sufficient rights to run a trace, then another option is to view the network traffic between the application that generates the SQL and box SQL Server is running on. WireShark works great for that.

Chris R. Timmons