database restore failing with move - sql

I am trying to restore a database backup but getting error:
Restore failed for Server 'ASIF-VAIO'.
(Microsoft.SqlServer.SmoExtended)
ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: File 'C:\Program Files\Microsoft SQL
Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\uwa.mdf' is claimed by
'Aston_Fresh_log'(2) and 'Aston_Fresh'(1). The WITH MOVE clause can be
used to relocate one or more files. (Microsoft.SqlServer.Smo)

When restoring, you need to be sure to
pick a new database name that doesn't already exist (unless you want to overwrite that pre-existing database)
you tick the Overwrite option in the Options tab page and define valid and new file names for the .mdf and .ldf file so that you don't accidentally overwrite another database on your system:

This post has some excellent answers but I don't believe my solution was covered here, or I didn't understand the answer/comment.
However, when I encountered this error I was restoring a database with 2 indexes (Primary and Index). The issue was that when restoring it had created two .ndf files, one for each index, but had named them the same thing.
So essentially I had two "Restore As" files restoring to "D:\MSSQLDATA\DatabaseName.ndf.
To overcome this I had to change one of the file names, so for example I changed
Index | D:\MSSQLDATA\DatabaseName.ndf
Primary | D:\MSSQLDATA\DatabaseName1.ndf
having unique file names fixed this for me.

This worked for me : giving a different name to each MDF and LDF file in the script section.
MOVE N'R_Data'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Build51_Testing_db1.mdf',
MOVE N'R_audit'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Build51_Testing_db2.mdf',
etc...
Originally suggested by Alberto Morillo

I know it's long since the last answer, but I happened to search in google for solution for this problem.
What did it for me, was scripting the restore (changing file name did not do the trick) and manually changing the filenames in code
RESTORE DATABASE [DB_NAME]
FILE = N'[name]',
FILE = N'[name1]',
FILE = N'[name2]'
FROM DISK = N'[file_path]'
WITH FILE = 1m
MOVE N'[name]' TO N'D:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\\[name].mdf',
MOVE N'[name1]' TO N'D:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\\[name1].mdf',
MOVE N'[name2]' TO N'D:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\\[name2].mdf',
MOVE N'[logname]' TO N'D:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\\[logname].ldf'
NOUNLOAD,
REPLACE,
STATS = 10
GO
Regards

If you have this issue and it's not the above, try under the Restore Options > Files, check the Relocate all files to folder checkbox.

In my case, there was already a .mdf and .ldf file in my \DATA folder, so I had to create two new files:
New-Item C:\path\to\sql\DATA\NewDatabase.mdf
New-Item C:\path\to\sql\DATA\NewDatabase_log.ldf
And then in the SQL manager you need to select those new files when restoring the database.

In my case, the database has 2 mdf files. And the error came, because I'm trying to restore both mdf files as the same name.
Just rename the second mdf file, under "Restore As".

Related

Create two identical databases from one backup file

For comparison purposes I'm trying to create two identical databases from one backup. The backup contains only one database.
Creating first database is going well.
When trying to create second database from the same backup file I get the error:
TITLE: Microsoft SQL Server Management Studio
------------------------------
Restore of database 'defaultDB' failed. However, the Tail-Log backup operation completed successfully. (Microsoft.SqlServer.Management.RelationalEngineTasks)
------------------------------
ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: The file 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\dbname.mdf' cannot be overwritten. It is being used by database 'dbname'. (Microsoft.SqlServer.SmoExtended)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=11.0.2100.60+((SQL11_RTM).120210-1917+)&LinkId=20476
------------------------------
BUTTONS:
OK
------------------------------
Do I have to change the mdf and ldf files to a new one?
Simply uncheck the option about "Take tail-log backup before restore" in the Options screen. A tail-log backup is used typically for when you have a log file (LDF) but a corrupt data file (MDF). It does not apply here
In the Files screen, rename the files (or path if you want). Each DB will have it's own MDFs and LDFs. This will rename the files on restore to avoid a conflict
The error comes from point 2, but point 1 applies here too. Doing a log backup each time will give different data in restore because changes (DDL or data) that happen between log backups
Change the path of the destination database i.e create a separate location and store the .mdf and .ldf files there, while creating the second identical database
Restore the identical database overwrite the second(with replace) under options tab

Backup/Restore from different database causing Restore failed exclusive access could not be obtained

I have a database A. I have taken a backup of database A called A.bak. I created a new database B. Now, I right click and Restore B from A.bak. In the Restore Dialog, I checked overwrite existing database and change the LogicalFileName from C:\Program Files\Microsoft SQL Server\MSSQL11.SQLSERVER2012\MSSQL\DATA\A.mdf to C:\Program Files\Microsoft SQL Server\MSSQL11.SQLSERVER2012\MSSQL\DATA\B.mdf and did the same with ldf file. But I am getting
Exclusive access could not be obtained because the database is in use.
Also tried,
ALTER DATABASE [B] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
Also sp_who2, there was no existing connection of [B]
A cause for the attempt to get exclusive access comes from the options page of the restore dialog in SQL Server 2012 Management Studio. It will turn on tail-log and leave in restoring state options for the SOURCE database. So, it will try to gain exclusive access to the source database (in this case A) in order to perform this action. If you turn off the tail log option, you will find that the operation works much more smoothly.
The answer was very simple,
Run this command to grab the LogicalNames,
RESTORE FILELISTONLY FROM DISK = 'C:\Users\MyUSer\Desktop\A.bak'
Then Just put the in LogicalName in below,
RESTORE DATABASE B
FROM DISK = 'C:\Users\MyUSer\Desktop\A.bak'
WITH
MOVE 'LogicalName' TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLSERVER2012\MSSQL\Data\B.mdf',
MOVE 'LogicalName_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLSERVER2012\MSSQL\Data\B.ldf'
GO
Note you might need to change the path. Helpful links,
How to restore to a different database in sql server?
http://technet.microsoft.com/en-us/library/ms186390.aspx
B. ’Restore Database’ Dialog will be displayed on the General page
1. The name of the restoring database appears in the To database list box. To create a new database, enter its name in the list box.
Select ‘From device’
Click button to display ‘Specify Backup’ Dialog
Click ‘Add’ to browse the .bak file from the directory and click OK

SQL Server 2000 backup recovering on SQL Server 2005

I've got a SQL Server database backup (file extension .bak) from an project of 12 y/a which I tried to restore on SQL Server 2005.
But this gave me an error that it was not the right version..
So I'm trying to find a SQL Server 2000 version to see if I can restore it with this but I can't find any version that works.
Is there another program to save my backup?
Copied over from msdn forums:
1) Go to restore database
2) Select the database that you want to back up to
3) Locate the backup file on disk. You may have to put it into the MSSQL Server -> MSSQL.1-> MSSQL -> Backup Folder. It must be a .bak file.
4) Select the back that want to restore from the available backups.
5) Go to the top left "options" property and when you do that select "overrite existing database".
6) Now make sure that the path to the files on database to be restored are correct in this same dialog view. Look at the paths to the database file and the log file and make damn sure that they are the correct ones for the database to be restored. The problem here is that those paths are going to be for the filesystem that the backup came from, not the one you are goning to put the restore onto.
Just to add to that, if you are restoring a database to a new server that does not have the database already in it (to restore to), create a sham database with the same name, then restore to it with the overwrite settings mentioned above.

Could not locate entry in sysdatabases for database 'mydb'

I had SQL Server 2005 on my pc and had created a few databases through it. Due to some problem, I had to reinstall it but now when i give the command "create database mydb" it says
"Cannot create file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\myDb.mdf' because it already exists. Change the file path or the file name, and retry the operation."
And when i give "use mydb" command it says
Could not locate entry in sysdatabases for database 'mydb'. No entry found with that name. Make sure that the name is entered correctly.
What should I do so that it can locate my databases?
I faced the same issue.
We need to use Square brackets for database name
ie
use [database]
instead of
use database
Hope it helps.
You can re-attach the database files (assuming that your current installation is at at least the same service pack/patch level as you previously had it).
You can attach the database using either Management Studio, or using CREATE DATABASE
When you re-installed the instance, it won't delete any existing database files and when you are creating a new database its complaining that the file already exists in the default path.
Go to the location C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\ and manually delete the myDB.mdf and .ldf files and next go ahead with creating a new database.
HTH
Sometimes I simply just get this issue because I didn't change the primary available database by pressing Ctrl+U into the new DB I created. Often helps to check.

MSDE backup file is appending

I have an MSDE 2000 database backup file which is appending rather than deleting or renaming. I am using this command:
BACKUP DATABASE [SPSDB] TO DISK = 'E:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\SPSbackup\spsdb.bak' with retaindays = 1
I am using a maintenance plan on my full SQL version databases, and they create a new file everyday with the date in the file name.
The backup file size creeps up on me if I don't monitor it. Is there a way to have MSDE make a uniue file with the daily backup job I created?
Thanks,
Chad
Take a look at http://msdn.microsoft.com/en-us/library/ms186865.aspx for the BACKUP command. Did you try using INIT option?
I noticed the question is very old, but maybe my answer can help somenone.