October 29, 2009 at 9:09 am
Is there a system stored procedure that I can use to find the last time a database was used?
Thanks,
Mon
October 29, 2009 at 9:28 am
Do you mean the last time someone "USE"d the database? Or ran a query?
There's a default trace in 2005. If you think it's been awhile, set AUTO CLOSE for that db. If someone uses it, then a message will get written into the log.
October 29, 2009 at 9:38 am
I mean, ran a query or logged into the database. The trace will show me any future usage, is there anyway I can trace what happened in the last couple of months.
October 29, 2009 at 9:47 am
No, when SQL starts it opens the db and that's it. It doesn't log the activity.
I'd set auto close and check the log periodically. After xx days, detach the db and then after yy days, remove it. Keep a backup.
October 29, 2009 at 10:43 am
Thanks Steve, I set the database to Auto-close. Could you tell me what events to capture in the trace? I was looking at Security Audit and then Audit Login/Logout?
Thanks,
Mon
October 29, 2009 at 10:59 am
Autoclose will actually write this in the error log for Windows. I don't see a trace event. Maybe capture any t-SQL batch in that db?
October 29, 2009 at 11:17 am
One other thing you can do is run a scheduled job to capture the output of sp_lock or it's equivalent dynamic management view. If the database is in use, a shared lock will be placed on the database to prevent another user from dropping it. I've had to do something similar in the past when trying to drop a database that someone had a lock on, but it wasn't readily available when looking at the databas connections.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply