How to see SQL query in SQL profiler?

25,040

Solution 1

you answered it, sql server tool called profiler

edit:

http://msdn.microsoft.com/en-us/library/ms187929.aspx

Solution 2

There are easier ways, if all you want is see the sql queries as they hit the DB.

Here are two very light-weight Sql profilers that can do the job for various SqlServer flavors, including LocalDb - "worked on my machine (TM)"

ExpressProfiler

By far the easiest to use one (and also the most bare-bones-show-me-the-SQL-statements-kthxbye) is ExpressProfiler on CodePlex.

Download tiny ZIP, wonder if you really got the whole file (you did), run EXE inside, BAM!

enter image description here

And the whole program is a single 126 KB EXE ! Now that's lightweight!

AnjLab Sql Profiler

The other one is the one from DataWizard, which used to be free (apparently prices now start at $5).

Somebody managed to save a snapshot on GitHub (including xcopy-installable binaries) when it was open-source.

The executable presents itself as "AnjLab Sql Profiler" and allows some filtering of the displayed events - but this strength is also its weakness, as there are sooo many event types that can be enabled/disabled. If everything is selected, the output is overwhelmingly verbose.

A saner output can be obtain by only selecting specific events.

enter image description here

Here are the events I have selected in order to get the above output:

enter image description here

Share:
25,040
Water Cooler v2
Author by

Water Cooler v2

https://sathyaish.net/?c=pros https://www.youtube.com/user/Sathyaish

Updated on July 09, 2022

Comments

  • Water Cooler v2
    Water Cooler v2 almost 2 years

    When I issue an update query or another Data Manipulation Language (DML) query that changes the data in the database, using Entity Framework 4, how do I see the query sent to the SQL Server?

    Let's say I do something like:

    someEntityObjectInstance.SomeProperty = newValue;
    context.SaveChanges();
    

    In this case, there's no ObjectQuery to do a ToTraceString() against, so I can't really see what's going on under the covers. I believe there's some Microsoft SQL Server tool like the profiler or something that will help me see the query.

    Also, some Intellitrace in VS 2010 Ultimate does the same thing, I think?

    Can you please teach me how to use the SQL 2005 Profiler, if there's any such thing?

    Update

    I am looking at a trace in SQL Server 2005 Profiler now but when I issue a context.DeleteObject() call or when I update an object and call context.SaveChanges(), I do not see the UPDATE or DELETE queries in the profiler. I only see wierd SELECT queries.

  • Water Cooler v2
    Water Cooler v2 over 13 years
    I am looking at a trace in SQL Server 2005 Profiler now but when I issue a context.DeleteObject() call or when I update an object and call context.SaveChanges(), I do not see the UPDATE or DELETE queries in the profiler. I only see wierd SELECT queries.
  • e-mre
    e-mre almost 13 years
    EF runs update statements with "exec sp_executesql" so you need to trace not only TSQL statements but also SP's to see update statements in the profiler
  • tough
    tough about 11 years
    @e-mre I would like to know what would "EF" mean here, I am too looking to see some update, insert and delete statements. I am able to see ´select´statements but not ´update, insert´and ´delete´statements.
  • e-mre
    e-mre about 11 years
    @tough EF is Entity Framework. EF runs some statements not as direct sql commands but rather through sp_executesql. For all these to appear in the profiler you might need to alter the default settings when starting a profiler session.
  • tough
    tough about 11 years
    @e-mre looking at the options on EF profiling I could not find anything stated with mssql-server-profiler, Julie Lerman explains different pro-filers used for EF but not mssql-server-profiler should I assume its not possible to trace any activity of EF though mssql-server-profiler?
  • e-mre
    e-mre about 11 years
    @tough The profiler I am talking about has nothing to do with EF. It is the profiler application that is installed with sql server client tools. "Sql Server Profiler".
  • tbone
    tbone about 8 years
    I'm working with an app that uses nhibernate and I also am completely unable to see any activity even though I have all stored procedure and TSQL events selected. UPDATE: I hadn't selected: Stored Procedures, RPC:Starting
  • WtFudgE
    WtFudgE almost 8 years
    mate, ur my hero, expressprofiler is the BOMB! super light weight and works like a charm, no hastle, nothing
  • Cristian Diaconescu
    Cristian Diaconescu almost 8 years
    @WtFudgE Glad you like it :)
  • riffrazor
    riffrazor over 4 years
    ExpressProfiler now seems to be source-only and has been moved to github.com/OleksiiKovalov/expressprofiler It compiled without issue and seems to work, though I still havent found update query syntax in its displays.