2

I have a table which get new data inserted every minute or so. According to the source code I have here, it is only done in one class which is not used anymore.

Is there any way to trace the inserts? What I mean is to see which queries they were inserted by, who sent those queries etc. As much info as possible.

I have tried several ways myself (e.g.sp_who2 'Active' stored procedure) without any success. I also have access to the machine running the SQL server and to the transaction backup files (.trn files) but have no idea how to open those files.

2 Answers 2

3

Add trigger to the table which follows inserts and insert to other table these variables:

getdate(),
host_name(),
App_Name(),
suser_sname()

Seems to me that this is enough

The trigger looks like this:

CREATE TRIGGER YourTrigger On YourTable
AFTER INSERT
AS
SET NOCOUNT ON;

   INSERT logtable
   SELECT APP_NAME(), HOST_NAME(), SUSER_SNAME(), GETDATE(), * FROM INSERTED
GO

OR

you can use Sql Server Profiler for catching the queries - it may be more flexible

5
  • Thanks for your reply Oleg. I tried the profiler and found similar queries but I cannot figure out who's sending them anyway...
    – Azimuth
    Jan 17, 2012 at 14:47
  • I tried this trigger but it doesn't output anything: CREATE TRIGGER [CatchTrigger] On [Customer_Email_Unsubscribe] AFTER INSERT AS BEGIN SET NOCOUNT ON; INSERT INTO temp_loginsert SELECT NULL, APP_NAME(), HOST_NAME(), SUSER_SNAME(), GETDATE(), sEmail, dUnsubscribeDate, iUnsubscribeID FROM inserted END
    – Azimuth
    Jan 17, 2012 at 15:31
  • It will not output something, it will write to log table, which you should periodically check
    – Oleg Dok
    Jan 17, 2012 at 18:40
  • Well obviously I meant that it doesn't write anything to the table
    – Azimuth
    Jan 18, 2012 at 7:29
  • Then nothing inserts to the table, OR there is a some error in the corresponding logtable structure - try for beginning to write something very simple in very simple table - just to check that it works
    – Oleg Dok
    Jan 18, 2012 at 7:33
0

You may use sp_depends like this:

sp_depends tablename

This only states information in the same database but it might say what you need!

5
  • Tried that but it only found one SP which selects from the table but doesn't insert anything...
    – Azimuth
    Jan 17, 2012 at 14:48
  • Then the insert may be in another database or from another application. Sorry for not helping more..
    – aF.
    Jan 17, 2012 at 14:50
  • Yes, the code which inserts into that table is in the VB class. I'm trying now to change the code to log every insert to see if all inserts are going through that class or some are going directly to the DB.
    – Azimuth
    Jan 17, 2012 at 15:04
  • @Azimuth do something like Oleg stated.
    – aF.
    Jan 17, 2012 at 15:07
  • I tried that but I got nothing in the logtable... guess I did a wrong trigger
    – Azimuth
    Jan 17, 2012 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.