to unlock mdf file being used by sqlserver

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i created a windows service. it uses a db which attaches a mdf file. i
created a installer for this service. it is installed successfully also. but
the problem is while i uninstall the application,it shows an error "mdf file
is being used by another process.".the lock is held by sqlserver. so
i want to check like this
pseudocode:
if(File.IsLock("abc.mdf"))
{
File.UnLock(abc.mdf);
}

How can i do this in c#
 
There is not way to unload *.mdf file if the SQL Server database using the
file is in use (meaing the database is attached to a SQL Server and the SQL
Server is running). You must detach the database from SQL Server, (stop SQL
Server so the file can be deleted. Not do not do it. Always detach
database).

So, you need to incoporate a SQL script into the uninstall process to detach
the said database first, as a custom action.
 
Back
Top