Pregunta

I was trying to restore a backup but I kept getting OS error 32 - cannot delete because in use.

Couldn't figure out what was locking the data and log files - so I rebooted the machine, stopped the service but still no luck.

Then I deleted the DB but data and log files are still there.

Rebooted again - tried to delete them but looks like there's no thing to do, windows doesn't let me.

Any idea?

¿Fue útil?

Solución

Antivirus software is one that catches DBAs - the MDF/LDF files are pretty big, and I've seen cases where the AV software grabs a lock on the files to scan them, but it takes forever due to the file size. You might try stopping your antivirus service.

Another one is backup programs - if you're using file-based backups (like Backup Exec or NetBackup) they may be trying to run a file backup at the time. Check for any backup software services, stop those, and then try to delete the files.

You might also have multiple instances of SQL Server installed, and this might belong to another instance, not the one you were working with.

Otros consejos

Use Process Explorer, a Microsoft tool that will tell you which process currently has a file locked, which will tell you what you need to stop/close before you can delete a file.

Here's a tutorial on finding out who has a file locked:

http://windowsxp.mvps.org/processlock.htm

I faced the similar error where I wasn't able to delete the datafiles and logfiles after the databases were detached.

I was getting the error saying "Administrator Privilege" is required.

It was resolved by changing the permission of the file. Go to run prompt -> type "windows explorer" -> Run as administrator and access the file.

Right click the filename and select "Properties'.Go to "Security Tab" and add your domain account with full permissions.

Now, you would be able to delete the file.

You should be able to detach (not delete) the database and then move or remove the data files.

Microsoft KB.

You deleted the DB's in SSMS but the files are still there? (shouldn't need to detach anymore if you "deleted" the entries" You probably checked the "Keep data files" checkbox

but I imagine a reboot should allow you to delete the actual .mdf and .ldf files If not, try booting into Safe mode and delete the actual files then

I encountered another reason for "in use by system" error. In my case I was not able remove file after detaching from all instances and rebooting. This was not security permissions problem. Nor it was used by any program as process explorer did not show any process using it. In my case the cause was improper check out of mdf by Visual Studio TFS. It seems if you checkout file and then loose connection to TFS server - you will not be able to delete or rename file with "in use by System". Even without VS started. File can be deleted in safe mode. And, what is more important - file can be unlocked properly if you get TFS back online and preform proper CheckIn.

I've encountered an error similar to this, but it was a permissions issue rather than anything else. Database was created under a different user, and the normal administrator account did not have permissions to LDF/MDF files at all.

Other symptoms were that administrator couldn't create a databasse of the same name, and that a third party application could not do a data import (as it dropped and recreated a database)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top