views:

930

answers:

2

I was running a trace on a Sql Server 2005 using the profiler and need to find out what is causing the reported errors.

I used the "blank" template, and selected all columns of the following events:

  • Exception
  • Exchange Spill Event
  • Execution Warnings
  • Hash Warnings
  • Missing Column Statistics
  • Missing Join Predicate

I noticed a number of these errors in the "TextData" column:

  • Error: 156, Severity: 16, State: 0
  • Error: 208, Severity: 16, State: 0

I looked up the errors (Incorrect syntax, Invalid object name), but how can I tell what stored procedure or query is causing them?

+1  A: 

in sql 2005 you can't. you'll have to run the profiler trace of SQL:StmtStarting, SQL:StmtCompleted, User Error Message and Exception events with text, transactionId, EventSequence and otehr columns you need to get a picture of what's going on.

Mladen Prajdic
I added SQL:StmtStarting and SQL:StmtCompleted, but only got "USE DBname". I switched to SP:Starting and SP:Completed, and got the commands.
KM
+4  A: 

Don't worry about the 208 errors. 208 is "Object not found". Profiler picks up these due to what's called 'deferred name resolution'.

Take the following procedure.

CREATE PROCEDURE Demo AS
  CREATE TABLE #Temp (ID int)
  INSERT INTO #Temp VALUES (1)
  SELECT ID FROM #Temp
GO

That proc will run fine without any errors however, if you have a profiler trace running, you'll see one or two instances of error 208. It's because the table #Temp doesn't exist when the proc starts, which is when the code is parsed and bound. The process of binding to the underlying objects fails.

Once the create table runs, the other statements get recompiled and bound to the correct table and run without error.

The only place you'll see that deferred resolution error is in profiler.

GilaMonster
The SPID seems to be the only way to correlate the 208 rows with the SP:Starting and SP:Completed rows. Using that, this seems correct, these 208s always seem to come just before a call to a stored procedure that uses temp tables.
KM
IIRC, there's a Connect item for removing these from Profiler because they are often misinterpreted and because they hide real 208 errors.
GilaMonster