Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft SQL Server > Re: capture and...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 6 Topic 10998 of 11517
Post > Topic >>

Re: capture and save running sql query to database table (for logging)

by "Plamen Ratchev" <Plamen@[EMAIL PROTECTED] > Apr 24, 2008 at 09:30 AM

You may not be able to do that in a trigger. In SQL Server 2005 you can get

the current statement with this query:

SELECT [text]
FROM sys.dm_exec_requests AS R
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS S
WHERE session_id = @[EMAIL PROTECTED]
 running this inside a trigger returns the SQL statement to create

the trigger.

The only statement that will actually output the current query is:

DBCC INPUTBUFFER(@[EMAIL PROTECTED]
);

But you cannot really store the result set from DBCC to a table.

One way to accomplish what you need is to set up a server side trace.

BTW, if the purpose of this is to prevent SQL injection attacks, you can
go 
the other way around and fix the code to prevent them rather than audit.

HTH,

Plamen Ratchev
http://www.SQLStudio.com
 




 6 Posts in Topic:
capture and save running sql query to database table (for loggin
=?ISO-8859-1?Q?Gear=F3id?  2008-04-24 02:12:29 
Re: capture and save running sql query to database table (for lo
"Plamen Ratchev"  2008-04-24 09:30:54 
Re: capture and save running sql query to database table (for
=?ISO-8859-1?Q?Gear=F3id?  2008-04-24 08:14:56 
Re: capture and save running sql query to database table (for lo
"Plamen Ratchev"  2008-04-24 22:34:49 
Re: capture and save running sql query to database table (for lo
"Plamen Ratchev"  2008-04-25 08:59:27 
Re: capture and save running sql query to database table (for
=?ISO-8859-1?Q?Gear=F3id?  2008-05-15 02:49:05 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 1:11:31 CST 2008.