Category Archives: Traces and Logs

>SQL Server: How to Read Trace File to Detect Database Detachment

>

On of our production server contains more then 200 databases. Few of them are rarely used but still required. Few days back, someone from DBA’s  team accidentally detached on of less used database. But once we need it we got error as there was no required database on server.
To find out, that when and who detached this database we have quickly executed a simple script.
First get current trace file name from sys.traces table
SELECT * FROM sys.traces
GO
Then copy trace file name and assign it @trace_file parameter and execute following script.
DECLARE @trace_file NVARCHAR(500)
SELECT  @trace_file = ‘C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Log\log_88.trc’
SELECT  *
FROM    [fn_trace_gettable](@trace_file, DEFAULT)
WHERE   TextData LIKE ‘%DETACH%’
ORDER BY starttime DESC

http://rcm.amazon.com/e/cm?t=co04b8-20&o=1&p=8&l=bpl&asins=B000071HPQ&fc1=000000&IS2=1&lt1=_blank&m=amazon&lc1=0000FF&bc1=FFFFFF&bg1=FFFFFF&f=ifrhttp://rcm.amazon.com/e/cm?t=co04b8-20&o=1&p=8&l=bpl&asins=B004U9USEA&fc1=000000&IS2=1&lt1=_blank&m=amazon&lc1=0000FF&bc1=FFFFFF&bg1=FFFFFF&f=ifrhttp://rcm.amazon.com/e/cm?t=co04b8-20&o=1&p=8&l=bpl&asins=1935182048&fc1=000000&IS2=1&lt1=_blank&m=amazon&lc1=0000FF&bc1=FFFFFF&bg1=FFFFFF&f=ifr

Advertisements