27

I am trying to view SQL generated by Linq to SQL in the SQL Server Profiler (2005).

I can see the sql sent to the server from anything except for linq to sql.

I'm betting that I need to change event selections for the trace, but not sure what else to select.

I am currently only selecting this: SQL:StmtCompleted - TextData & SPID

I don't want to use data context logging nor the SQL Debug Visualizer. I need to use the profiler.

Why can I not see the LINQ to SQL queries?

Thanks.

EDIT

I added SQL:BatchCompleted and that hasn't helped.

EDIT 2

I added the event RPC:Completed which is found under the Stored Procedures category in event selection. This worked!

Community
  • 1
  • 1
Ronnie Overby
  • 45,287
  • 73
  • 267
  • 346

4 Answers4

37

You need RPC call - the queries are executed as exec_sql.

cjk
  • 45,739
  • 9
  • 81
  • 112
  • Figures...I'd still expect stmt completed to work surprised it doesn't – JoshBerke Apr 08 '09 at 13:02
  • 1
    For SQL Server Profiler 2017 (v14.0.17099) add the RPC:Starting property like so: Menu \ File \ Properties \ Events Selection \ Stored Procedures \ [X] RPC:Starting. Run – Micah Epps Jul 26 '19 at 13:00
2

Are you including enough of the options in the SQL Profiler to see the BatchCompleted events, too?

Marc

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
1

There is also an option in the data context class to enable log in the client side. When log is enabled is possible to see the queries.

See this link:

http://www.davidhayden.com/blog/dave/archive/2007/08/17/DataContextLogLoggingLINQToSQLOutputConsoleDebuggerOuputWindow.aspx

0

Had the same problem and none of the solutions above worked for me.

What worked for me was adding ToList() enumerator to the query.

Before:

var data = null == id ?
                   (from ...
                    select new
                    {
                        ...
                    })
                :
                   (from ..
                    select new
                    {
                        ...
                    });

After:

var data = null == id ?
                   (from ...
                    select new
                    {
                        ...
                    }).ToList()
                :
                   (from ..
                    select new
                    {
                        ...
                    }).ToList();

foreach (var obj in data)
{
   xxx = obj.somename; --> now you can see the sql query in Profiler
live-love
  • 48,840
  • 22
  • 240
  • 204