Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Profiler Trace


Reply
 
Thread Tools Display Modes
  #1  
Old 03-24-2005, 05:43 AM
CyberDogg CyberDogg is offline
Centurion
 
Join Date: Jun 2004
Posts: 189
Default Profiler Trace


I know this is a bit unrelated to vb but I really need help and I know theres a few gurus out there.

Basically I have had data mysterously change with no reason, so as it had caused me over 4 hrs of work I added a trace to the database, a few nights later the same thing happened, now I found the entry that shows what happened from the trace which is here

RowNumber EventClass TextData NTUserName ClientProcessID ApplicationName LoginName SPID Duration StartTime Reads Writes CPU EventSubClass DatabaseName LoginSid
111852 41 UPDATE L320_Broadcast SET Printed = 0 2976 MS SQLEM - Data Tools sa 68 47 24/03/2005 02:15:42 6613 89 47 <Binary>

Now from this, I understand that there was a client on the network using enterprise manager which had the sa login details and was used to ru nthe update query. I assume i am correct?

So my question is can I find out anything about that client? I need to find an IP or computername or something so I can identify the PC it came from. You can see the NT user name wasnt logged I suspect this is because it was done via a vpn. Any help will be much appreciated.
Reply With Quote
  #2  
Old 03-24-2005, 05:59 AM
00100b's Avatar
00100b 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

If you are capturing the trace information to a table versus a file, then you could use an Insert Trigger on that table to invoke and capture the results of the sp_who stored procedure passing it the SPID from the trace event record. Contained within the results of sp_who is the field 'hostname'.
__________________
The only stupid question is the one that goes un-asked.
Reply With Quote
  #3  
Old 03-24-2005, 06:19 AM
CyberDogg CyberDogg is offline
Centurion
 
Join Date: Jun 2004
Posts: 189
Default

Unfortunately I was running the trace to a file due to the amount of activity it would have caused on the database server.

So unless I captured the data in realtime theres no way to trace back to an IP or hostname?
Reply With Quote
  #4  
Old 03-24-2005, 10:04 AM
00100b's Avatar
00100b 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

I have not found (yet) where you can include the IP or hostname in the data generated by a trace event.

A method that I employ is to include an "Audit Trail" within the database itself. Using triggers and the @@SPID global variable, I am able to then query the results of sp_who and the sysprocesses table for that SPID and populate fields (either within the same record or records in other tables). This provides real-time tracking and allows you to get as granular as you want (within what data is available of course).
__________________
The only stupid question is the one that goes un-asked.
Reply With Quote
  #5  
Old 03-24-2005, 12:16 PM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,386
Default

As 001001b suggested, add the audit trail within the database itself.

Here's an example of one method I use:

First, add an audit table. In this example, tblAudit contains 4 fields: fld_PKID (int, identity), fld_TimeStamp (datetime), fld_User VarChar(100), and fldHost Varchar(100)

Then, add a trigger to the table that you wish to audit. Ex:
Code:
use Your_Database_Name
GO

If Exists 
	(	Select Name from sysobjects 
		where name = N'Your_Trigger_Name' and Type = 'TR' )
	DROP TRIGGER Your_Trigger_Name 
GO

CREATE TRIGGER Your_Trigger_Name ON YourTableName 

FOR INSERT, UPDATE  
AS 
	Begin
		DECLARE
		@HOSTNAME VARCHAR(100),
		@APPNAME  VARCHAR(100)

		set @HOSTNAME = host_name()
		set @APPNAME = APP_NAME()

		INSERT INTO tblAudit
		(	fld_TimeStamp,
			fld_User,
			fld_Host
		)
      	   Values
		(
			CURRENT_TIMESTAMP,
			SESSION_USER + ':' + SYSTEM_USER,
			@HOSTNAME + ':' + @APPNAME
		)
 
	END
GO
Obviously, you'll need to change Your_Trigger_Name, YourTableName, and Your_Database_Name to your actual object names.

After I updated a field and added a few fields in the table I was auditing, here's the results:
Code:
select * from tblAudit

fld_id_pk fld_TimeStamp fld_User                                                     fld_Host                                                     
--------- ------------- ------------------------------------------------------------ ------------------------------------------------------------ 
1         3/24/2005 11: dbo:TALLEYDS\loquin                                          LOQUIN:MS SQLEM - Data Tools
2         3/24/2005 11: dbo:master                                                   LOQUIN:Query Express
3         3/24/2005 11: dbo:master                                                   LOQUIN:Query Express
4         3/24/2005 11: dbo:master                                                   LOQUIN:Query Express

4 row(s)
In the first case, I was logged on using windows authentication using Enterprise Manager to update a record, in the remaining three records, I was logged on with SQL Server authentication, using Query Express to insert new records. The fld_Host column contains the windows computer name, which may be of benefit. (interestingly, the SQL Server HOST_NAME function returns the name of the workstation, and not the name of the server.)

Since you might be accumulating a large abount of data in the database, you might want to alter the above trigger so that it ONLY adds an audit record if the user is 'sa'. Or, alter it to only add a record if it's an update, rather than an insert. (This wouldn't catch any changes that are accomnplished by deleting an existing record, then adding a new record in its place, though)

In addition, you'll probably want to enable (for the moment, anyway) under the security tab of Server properties in EM, All auditing level.

And, after you get a day's data or so, you should probably alter the sa password...
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown

Last edited by loquin; 03-28-2005 at 08:46 AM.
Reply With Quote
  #6  
Old 03-27-2005, 10:55 PM
Aseen Aseen is offline
Junior Contributor
 
Join Date: Feb 2005
Location: Philippines
Posts: 305
Default

at the Trace Properties (after connecting to the server)
at the Data Columns Tab...
add HostName from the unselected data to selected data

i hope that, that's what you meant
and i hope it will work too
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->