1

I am trying to copy a database from one folder to another. There is no program at all running except operating system.(I mean all windows shut)

I keep getting this :

The action cannot be completed because the file is open is another program close file and try again

Multiple attempts results in the same error.

What could be keeping that file open and how can I carry on with copy / delete / overwrite files(DB) as this problem is something very common.

5 Answers 5

7

Try net stop mssqlserver /y and see what happens. Naturally I'm assuming here it's okay to stop the DB server.

2
  • I think this is very likely going to be the resolution despite the tools suggested for checking what the file is being locked by.
    – tcnolan
    Feb 10, 2010 at 23:27
  • net stop mssqlserver works , though I don't think /y does anything and /? doesn't mention a /y.
    – barlop
    Apr 28, 2018 at 21:00
3

Go to Task Manager and see, it's sqlservr.exe proccess is running. If so, kill it and try again. Also there is a useful small program called 'Unlocker' which allows to look which proccesses are attached to the file, kills them and let the file be deleted or moved.

A similar tool is WhoLockMe!

1
  • I've used those tools as well pretty good...
    – tcnolan
    Feb 10, 2010 at 23:24
2

This error can be solved by stopping MSSQLSERVER service form configuration Tool in Microsoft Sql Server as shown with diagram in the link below:

Solve Error The action can’t be completed because the file is open in SQL SERVER(MSSQLSERVER)

enter image description here

Some time while moving a database (.mdf) from one location to other location on hard disk drive you encounter with the error ‘The action can’t be completed because the file is open in SQL SERVER(MSSQLSERVER) ‘ as shown in the diagram below:

The action can’t be completed because the file is open in SQL SERVER

Steps to solve error ‘The action can’t be completed because the file is open in SQL SERVER’ as shown in below: Step 1: Click on Start Icon on the task bar . Select Microsoft SQL Server folder and then click on SQL Server Configuration Manager as shown in the picture below:

The action can’t be completed because the file is open in SQL SERVER

enter image description here

Step 2: SQL SERVER Configuration Manger window will open on the left side of this window select SQL Server Services . In SQL server services right click on the service SQL Server (MSSQLSERVER) and click on Stop as shown in the picture below:

The action can’t be completed because the file is open in SQL SERVER

enter image description here

Step 3: As the process will stop move the file from one location to other and then again start this process by right click on it. Email ThisBlogThis!Share to TwitterShare to Facebook

1
  • 1
    Thanks for your answer. In case the site you linked to should ever go away, it's better to repost the image in your answer. Dec 29, 2013 at 15:57
1

Open the Microsoft SQL Server Management Studio,then open Object Explorer .Right Click and you can find Restart the connection.This will stop the SQL Server and you can delete or transfer the database.

0

I usually prefer to use first party tools for this kind of thing, process monitor from sysinternals is my tool of choice for this kind of thing. Just watch out if you have a lot of background services running cause you will see lots of activity going through. Really useful for watching your registry as well.

http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .