October 8, 2009 at 12:31 pm
Hi,
i want to select all mdf files in a folder and check their property with
dbcc checkprimaryfile to attach them,the problem is that this command dosen't work on locked(used mdf file).
i need to remove the check on locked mdf files.
is there a way to check if a file is used or locked through the SQL?
mybe through xp_cmdshell?
THX
October 9, 2009 at 7:04 am
Sounds like something you should be doing in PowerShell. Since you haven't actually shared a script it is a bit hard to comment on how you'd implement the check. A query like this would give you the file names of all databases that are offline, which means the files should not be locked:
SELECT
S.[name],
S.filename
FROM
sys.databases AS D JOIN
sys.sysaltfiles AS S
ON D.database_id = S.dbid
WHERE
D.state_desc <> 'ONLINE'
If you are looking for database files that have never been attached to the database instance then you could just get the list of ONLINE databases and skip those files.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply