Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Other Technologies / Service Broker / May 2008

Tip: Looking for answers? Try searching our database.

Not able to catch the client hostname when using Service Broker for Auditing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Javier - 06 May 2008 13:37 GMT
Hi,

I did set Service Broker (SB) to insert into a table all the changes on my
user objects.

I have created the Queue, the service, the event notification and the
activation stored procedure as described below

My problem is that the activation procedure can not capture the client
hostname (this is very usefull to get who changed an object)

Any idea????
ALTER PROCEDURE dbo.SP_DBA_NS_Audit

AS

BEGIN

DECLARE @eventDataXML XML, @hostname nvarchar(128), @spid smallint ;

RECEIVE TOP(1) @eventDataXML=message_body

FROM NS90.dbo.AuditQueue

IF CAST(@eventDataXML as XML) is not null

BEGIN

SELECT @spid = @eventDataXML.value('(/EVENT_INSTANCE/SPID)[1]','int')

SELECT @hostname = host_name FROM sys.dm_exec_sessions where session_id =
@spid

INSERT INTO NS90.dbo.DBA_NS_Audit (LogTime, ObjectName,spid,hostname,
eventXMLData)

VALUES
(getdate(),@eventDataXML.value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(100)'),@spid,@hostname,cast(@eventDataXML
as XML));

END

END;

CREATE QUEUE NS90.dbo.AuditQueue

WITH STATUS = ON,

ACTIVATION (

procedure_name = NS90.dbo.SP_DBA_NS_Audit,

MAX_QUEUE_READERS = 1,

execute as self )

ON [DEFAULT] ;

CREATE SERVICE

AuditService ON QUEUE dbo.AuditQueue

([http://schemas.microsoft.com/SQL/Notifications/PostEventNotification]);

CREATE EVENT NOTIFICATION ENDBAudit

ON SERVER

FOR

CREATE_FUNCTION,

ALTER_FUNCTION,

DROP_FUNCTION,

CREATE_INDEX,

ALTER_INDEX,

DROP_INDEX,

CREATE_PROCEDURE,

ALTER_PROCEDURE,

DROP_PROCEDURE,

CREATE_TABLE,

ALTER_TABLE,

DROP_TABLE,

CREATE_TRIGGER,

ALTER_TRIGGER,

DROP_TRIGGER,

CREATE_VIEW,

ALTER_VIEW,

DROP_VIEW

TO SERVICE 'AuditService', 'current database';
Roger Wolter[MSFT] - 07 May 2008 17:11 GMT
There's no way to get the client information as part of an event
notification.

Signature

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

> Hi,
>
[quoted text clipped - 103 lines]
>
> TO SERVICE 'AuditService', 'current database';
Roger Wolter[MSFT] - 07 May 2008 22:52 GMT
I assume someone will say that you can use the SPID from the event to look
up the client in sys.processes but because events are asynchronous, that
won't always work reliably.

Signature

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

> There's no way to get the client information as part of an event
> notification.
[quoted text clipped - 106 lines]
>>
>> TO SERVICE 'AuditService', 'current database';
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.