I used sp_detach_db
to detach SQL Server 2005 databases. This works properly in Windows XP and Windows 7.
However, the same fails in Windows Server 2008. The error message states:
The process cannot access the file SimpleProject_device.ldf as it is being used by another process
But, I am able to delete both .mdf and .ldf files manually inspite of getting this error. I guess, if the database was still attached, delete operation should not have been allowed by the OS.
Edit: The problem was that the Connection object had been disposed before detach. (God knows how). Therefore, I have added a condition to ensure that the connection exists before trying to detach the database.
Currently, I am getting another error.
An error occurred during database detach: "A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)",30791590,8688858,5/22/2012,9:37:05 PM
Does anyone know why I'm getting this error?