Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 Tracking down a query in code

Author  Topic 

ferrethouse
Constraint Violating Yak Guru

352 Posts

Posted - 2011-12-16 : 12:30:11
I'm at wits end trying to find where a troublesome query is being executed from (.NET code, database object, etc.). We have 10 developers on staff and I've asked all of them to stop what they are doing and track down the query and nobody can find it. I'm pretty sure that it is LINQ (based on the way Ignite formats it) so that rules out a database object. Is there a way to not allow SQL Server to execute that query. I'd rather have a component of our application break temporarily in order to find out where it is coming from.

I've used profiler to try to isolate when it happens but it doesn't reveal any useful patterns. It does happen several hundred times per hour but it hasn't been useful for know what is executing it.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-16 : 12:34:02
Profiler can give you the hostname and application name. The application name will only show a value if they have specified it in the connection string. But you will at least get a good hostname from Profiler. So that at least tracks it down to a single server.

The hostname column is not a default column, so you have to add it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-12-16 : 13:47:10
and yet ANOTHER reason to only code using stored procedures

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

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

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-12-18 : 23:38:27
quote:
Originally posted by ferrethouse

I've used profiler to try to isolate when it happens but it doesn't reveal any useful patterns.



Might be worth looking at the SPID when you find an execution in Profiler, and then what that SPID was doing immediately before/after - if the application executes something else that includes the offending code then the other activity on that SPID would help you track it down.

Does all the database access in the application go through a single function? (our does ...) if so that might be a place (or relatively "few places") to trap it.
Go to Top of Page

ferrethouse
Constraint Violating Yak Guru

352 Posts

Posted - 2011-12-20 : 18:17:10
Thanks for the feedback. Everything comes from the same application unfortunately (a web app). One of our developers did manage to track it down by using the profiler and some serious detective work. Of course, that was only after I offered a 500 gig hard drive to the person able to find it ;)
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2011-12-20 : 19:20:44
OR.... Issue a KILL on that spid and listen for who starts to howl. Just a thought.

=======================================
Faced with the choice between changing one's mind and proving that there is no need to do so, almost everyone gets busy on the proof. -John Kenneth Galbraith
Go to Top of Page
   

- Advertisement -