You are here: Re: Finding prepared statement sql « MsSQL Server « IT news, forums, messages
Re: Finding prepared statement sql

Posted by Erland Sommarskog on 10/02/92 11:49

birju (floating.buddha@gmail.com) writes:
> The statement is prepared before I start the profiler and the client
> keeps that connection - so I can't see its preparation without
> restarting the server (it's a web application).

Aha. Thanks for the clarification.

It occurred to me one thing that you could try, although I'm not sure
that it works with prepared statements, and that is the function fn_get_sql
that was introduced in SQL 2000 SP3.

From sysprocesses you get a handle, and two statement offsets, start
and end. You feed the handle to fn_get_sql, and get back a table with
object id for the current stored procedure (if applicable), and the text
of the current scope. Then you use the offsets to get the exact statement.

I have it all packaged in a stored procedure aba_lockinfo, that you can
download from http://www.sommarskog.se/sqlutil/aba_lockinfo.html. You
cannot correlate directly with Profiler, but long-running statements are
more likely to turn up in the snapshot it produces.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация