Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to audit access to all objects in a database?

$
0
0

I want an audit file row each time an object is accessed in a database. I have this code running in SQL2008R2. I am testing in a database called SQLAudit.

USE [master]
GO
CREATE SERVER AUDIT [UserAccessAudit]
TO FILE 
(	 FILEPATH = N'C:\SQLData\SQL2008R2\AuditLogs\Audit'
	,MAXSIZE = 100 MB
	,MAX_ROLLOVER_FILES = 2147483647
	,RESERVE_DISK_SPACE = OFF
)
WITH
(	 QUEUE_DELAY = 1000
	,ON_FAILURE = CONTINUE
);
GO

CREATE SERVER AUDIT SPECIFICATION [UserAccessAuditSpecification]
FOR SERVER AUDIT [UserAccessAudit]
   ADD (DATABASE_OBJECT_ACCESS_GROUP) 
WITH (STATE = OFF);
GO

ALTER SERVER AUDIT SPECIFICATION [UserAccessAuditSpecification]
FOR SERVER AUDIT [UserAccessAudit]
WITH (STATE = ON);



USE SQLAudit;
GO

CREATE DATABASE AUDIT SPECIFICATION [UserAccessAuditSpecificationDatabase]
FOR SERVER AUDIT [UserAccessAudit]
	  ADD (SELECT, UPDATE, INSERT, DELETE, EXECUTE, RECEIVE, REFERENCES ON DATABASE::SQLAudit BY PUBLIC);

ALTER DATABASE AUDIT SPECIFICATION [UserAccessAuditSpecificationDatabase]
FOR SERVER AUDIT [UserAccessAudit]
WITH (STATE = ON);

This only captures table and stored procedure access. I need access to views and all the varieties of functions, synonyms etc.
Thanks

Tom


Tom G.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>