Sql-server – Why is SQL Profiler showing empty for database name and database id

profilersql serversql-server-2008-r2

I have some code that uses Entity Framework to call a stored procedure in SQL Server. If I run SQL Profiler and filter by the database it is calling, I can see that the profiler correctly shows the call.

However, the database name and database id column are always empty. Anyone know why it is not showing this information?

I'm using this version:

Microsoft SQL Server 2008 R2 (SP1) – 10.50.2500.0 (X64) Jun 17 2011
00:54:03 Copyright (c) Microsoft Corporation Standard Edition (64-bit)
on Windows NT 6.1 (Build 7601: Service Pack 1)

Best Answer

Confirm the trace is actually gathering those columns. The following query will show the events and columns being captured for each trace (except the default system trace):

SELECT TraceID = t.id
    , TracePath = t.path
    , EventName = te.name
    , ColumnName = tc.name
FROM sys.traces t
    CROSS APPLY sys.fn_trace_geteventinfo(t.id) ei
    LEFT JOIN sys.trace_events te ON ei.eventid = te.trace_event_id
    LEFT JOIN sys.trace_columns tc ON ei.columnid = tc.trace_column_id
WHERE t.id > 1 /* exlude the system trace */
ORDER BY t.id
    , ei.columnid;

The results look something like this (depending on the events and columns you've defined for your trace):

╔═════════╦═════════════════╦═════════════╦═════════════════╦═════════╦══════════╗
║ TraceID ║    TracePath    ║  EventName  ║   ColumnName    ║ eventid ║ columnid ║
╠═════════╬═════════════════╬═════════════╬═════════════════╬═════════╬══════════╣
║       2 ║ C:\temp\trc.trc ║ CursorClose ║ ApplicationName ║      78 ║       10 ║
║       2 ║ C:\temp\trc.trc ║ CursorClose ║ SPID            ║      78 ║       12 ║
║       2 ║ C:\temp\trc.trc ║ CursorClose ║ EventSequence   ║      78 ║       51 ║
╚═════════╩═════════════════╩═════════════╩═════════════════╩═════════╩══════════╝