Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The process cannot access the file '.mdf' because it is being used by another process

I use the ASP.NET Dynamic Data web template with an SQL Server 2008 database and when I try to add .mdf file in App_Data I get

The file cannot be opened because it is being used by another process. Please close all applications that might access this file and try again

I try find solutions but its very different

Hi Ken, this is because you are trying to add your DB to the project (i.e. copy it there) not connect to it, to connect add a Entity Framework data model and then select your Data base and all should go well.

If you actually want to have the DB in the App_Data folder then you will need:

To have SQL Server Express installed locally and on your web server. Temporarily stop your SQL Server so that the DB is accessible then copy it to the App_Data folder.

Or

  1. Go to SQL Server Configuration Tools and stop the SqlserverExpress Service.

  2. In Solution Explorer a Right click on project add existing Item ., Go to Program files and search for you required .mdf file in it add it to Project.

  3. Goto SQL Server Configuration tools start the Sqlexpress Service.

  4. Run Your solution.

How I can resolve my issue?

like image 389
Ray Avatar asked Dec 09 '12 09:12

Ray


2 Answers

The easiest way to find the process that is using the file is to:

  1. Run 'resmon'. (Use the windows search to find the program)
  2. Type the name + extenstion into the searchbar inside the second tab
  3. The result will be the proces that is using that file.

(yes i know this is an old question)

like image 180
John Doe Avatar answered Nov 14 '22 23:11

John Doe


If you have accessed this mdf file before using either Sql Management Studio or your Visual Studio xx. Then please close Sql Server running this mdf file, I mean, you have to stop the Sql Server Services and then copy the mdf file from its location to the desired location.

After copying, you can very well restart the Sql Server.

like image 21
Kishore Kumar Avatar answered Nov 14 '22 23:11

Kishore Kumar