Cannot restore database with .mdf extension in sql server - sql-server

I have back-up my database from LocalDB server which is .mdf file:
C:\THESIS - SOURCE CODE\SIS-JEN\SIS\APP_DATA\SIS_DB.MDF
and it was successfully backed-up with an extension of .bak:
C:\THESIS - SOURCE CODE\SIS-JEN\SIS\APP_DATA\SIS_DB.MDF.bak
Now, I want to restore this back-up file to the new server(my pc/server), but I cannot successfully restore using the .bak file:
C:\THESIS - SOURCE CODE\SIS-JEN\SIS\APP_DATA\SIS_DB.MDF.bak
I've got this error:
Restore of database 'C:\THESIS-SOURCE
CODE\SIS-JEN\SIS\APP_DATA\SIS.DB.MDF' failed
Can anybody help me to fix this error?

Check about RESTORE statement -
USE [master]
GO
RESTORE DATABASE [SIS_DB] FROM DISK = N'D:\SIS_DB.bak'
WITH FILE = 1,
MOVE N'SIS_DB' TO N'D:\SIS_DB.mdf',
MOVE N'SIS_DB_log' TO N'D:\SIS_DB_log.ldf', NOUNLOAD

Related

I can not restore my database SQL Server Management Studio can't recognize my .bak files

I'm trying to restore a DB from the class. However, when I try to restore the .bak file, it seems like SSMS doesn't recognize it.
I gave full permissions to the folder which contains the .bak file (it is the default backup folder of ms SQL studio).
Steps I've taken to restore the .bak file:
Right click on DB -> Restore DB -> From device (selected the .bak file location) -> To Database (selected the DB destination)
Like here:
C:\Program Files (x86)\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Backup
The DB is not corrupt I checked 2 other DB same result so I have no idea what is the problem
Here images:
I can not see the DB and I have almost the latest version of MS SQL studio so I can not understand what is going on here and why I can not restore DBs
I checked here:
restore database in ssms 2017 selected bak file in device option and showing nothing in Backup sets to restore option and disable Ok button too
and here:
SQL Server Management Studio can't recognize .bak file
https://www.youtube.com/watch?v=U0FpXwQfBaU
It should be easy and simple like the video above but like I said above something is wrong here and I do not know what is it.
Image of my SQL version
Once you (i mean the service account) got full permissions on the folder where the .bak file sitting and file not corrupted you should be able to restore without any issue, but there are times things fail in GUI and work perfectly with command line. not sure the issue might be exists one of the fix of SSMS release notes
However, you probably want to try following:
Verify the backup file - it does the verification of backup file and detects any error/corruption within backup file
RESTORE VERIFYONLY FROM DISK = 'C:\YourbackupLocation\DbName.bak';
Read the header - it returns information of backup file i.e. DB Version, appended backup files, LSN info and database recovery model etc..
RESTORE HEADERONLY FROM DISK = 'C:\YourbackupLocation\DbName.bak';
Get list of file names from backup - This will be helpful if the file location is different from the source server from where the backup was created
RESTORE FILELISTONLY FROM DISK = 'C:\YourbackupLocation\DbName.bak' ;
Restore backup - actual restore via T-SQL
RESTORE Backup DBName FROM DISK = 'C:\YourbackupLocation\DbName.bak' with replace, recovery, stats;
To relocate files
RESTORE Backup DBName FROM DISK = 'C:\YourbackupLocation\DbName.bak'
with replace, recovery, stats
--- Get the logical name from the result of "RESTORE FILELISTONLY" command
move 'DBName' to 'C:\NewLocation\DBName.mdf',
move 'DBName_Log' to 'C:\NewLocation\DBName_log.ldf' ;

Cannot restore mssql database because .mdf file is missing

I am trying to backup a database from SqlServer 2014 (in Windows 10 OS) and restore it to SqlServer 2017 (in Ubunutu 18.04 Digital Ocean).
I'm used the following SQL Command to Backup:
USE [master]
GO
BACKUP DATABASE [SampleDb] TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\Backup\SampleDb.bak' WITH CHECKSUM, COPY_ONLY, FORMAT, INIT, STATS = 10;
I'm trying to use the following SQL Command to Restore:
RESTORE DATABASE [SampleDb] FROM DISK = '/home/faizan/SampleDb.bak' WITH CHECKSUM, MOVE 'SampleDb_Data' TO '/home/faizan/SampleDb_Data.mdf', MOVE 'SampleDb_Log' TO '/home/faizan/SampleDb_log.ldf', RECOVERY, REPLACE, STATS = 10;
However, I'm getting the following error in my Ubuntu server when I try to restore the database:
When I ran the following Command to check the status of the .mdf and .ldf files,
RESTORE FILELISTONLY FROM DISK = '/home/faizan/SampleDb.bak'
I get the following result:
I am an ubuntu newbie and I don't see an mdf file here at all. And when I try to restore without the mdf file I get an error.
So how do I restore this Mssql backup in ubuntu when the .mdf file is missing?
(Extra note: The SampleDb.mdf file is present in Windows 10, in C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\DATA, it just doesnt get transfered to Ubuntu)
This issue is not really Ubuntu-specific, it would appear also on Windows boxes.
There is one small thing to fix in your RESTORE script. The logical name of MDF file is according to a screenshot is SampleDb but not a SampleDb_Data.
Therefore adjusted command is:
RESTORE DATABASE [SampleDb] FROM DISK = '/home/faizan/SampleDb.bak'
WITH CHECKSUM
, MOVE 'SampleDb' TO '/var/opt/mssql/data/SampleDb_Data.mdf'
, MOVE 'SampleDb_Log' TO '/var/opt/mssql/data/SampleDb_log.ldf'
, RECOVERY, REPLACE, STATS = 10;
Update: As Larnu remarked, another thing to consider is the location of the database files. MSSQL user should have read/write access and /var/opt/mssql/data is a default location for such files.

Restoring .File Extension SQL Server have empty content

Can someone help me restore this backup database?
I backup my database to my D drive it created file with .file extension after that i uninstall my sql server then re install it when i try to restored the database it showed no database.
i ve tried to restore using File and Filegroups but there is no database to select.
this is my file
https://drive.google.com/file/d/0B-VCua2N1hePQjNxa3hCSy0tZjQ/view
it only contain created table with no data
Run something like this, just specify correct path to a file and where to restore a database:
USE [master]
RESTORE DATABASE Test FROM
DISK = N'D:\....\TreasuryDB' WITH FILE = 1, NOUNLOAD,
MOVE N'TreasuryDB' TO N'D:\....\Data\Test.mdf',
MOVE N'TreasuryDB_log' TO N'D:\....\Log\Testlog.ldf'

no backup selected for restore sql server 2012

I am trying to restore db from my db backup file when i select and add the db .bak file
I have seen that error "No back upset selected to be restored"
I also tried from script to restore it but failed.
kindly tell me some effective way to do that??
I have already tried this but failed
RESTORE DATABASE <Your Database>
FROM DISK='<the path to your backup file>\<Your Database>.bak'
Try RESTORE HEADERONLY to see if there are several backup sets in your bak file
RESTORE HEADERONLY
FROM DISK='<the path to your backup file>\<Your Database>.bak'
http://msdn.microsoft.com/en-us/library/ms178536.aspx
and if there are several sets, choose the one you want :
RESTORE DATABASE <Your Database>
FROM DISK='<the path to your backup file>\<Your Database>.bak'
WITH FILE = <you set number>;

VB.NET restore Backup file created on one server to another server

i am using SQL server express 2005 as an backend. I created a backup file programmatically.If i use same server , then it restore the data successfuly. however if we try to restore on different server, then it fails. and throw following message
"The Backup set Holds a backup of a database other than the existing 'DatabaseName' database. RESTORE DATABASE is terminating abnormally."
On both server, Sql server instance name and database name is same.
Please suggest how can i resolve this error
You need to RESTORE from files (which are contained in the backup set) rather than the backup set directly. The bottom example is to copy a database, but the idea is the same.:
BACKUP DATABASE AdventureWorks
TO AdventureWorksBackups ;
RESTORE FILELISTONLY
FROM AdventureWorksBackups ;
RESTORE DATABASE TestDB
FROM AdventureWorksBackups
WITH MOVE 'AdventureWorks_Data' TO 'C:\MySQLServer\testdb.mdf',
MOVE 'AdventureWorks_Log' TO 'C:\MySQLServer\testdb.ldf';
GO

Resources