.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Restore of database backup done by script failed

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :


In my C++ application (with MFC) developed in Visual Studio 2010 the user has an option to take a backup of the current database. This is done by executing a Stored Procedure which takes the database name and backup file name as parameters:

CREATE PROCEDURE sp2_backup_database @DATABASE nvarchar(100), @FILENAME nvarchar(260)
  Exec ('Backup Database [' + @DATABASE + '] TO  DISK = '' + @FILENAME + ''
      '-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10')
   Return @@ERROR

All this works fine, the backup is done properly by the SP.
What is bothering me is that when trying to make a restore of the database from the backup file the restore fails with a message like (freely translated from Swedish):

"Restore failed for [the SQL Server]. (Microsoft.SqlServer.SmoExtended)
Additional information:
System.Data.SqlClien.SqlError: RESTORE can not process the database [Database-name] since it's in use by this process. It's recommended to use master database during this task."

The only way I can

View Complete Post

More Related Resource Links

Restore Database Backup using SQL Script


I need to backup a database using query.Please help me.

Restore database backup with Copy_Only option failed ?


When we failed to restore a backup from a BAK file for SQL Server 2008.


Then we find that the backup is created by using BACKUP xxxx COPY_ONLY parameter.  When we attempt  to restore from Management Studio (with the database changed to single user mode), we get the error message "There is NOTHING in the "Select the backup sets to restore".


We would like to seek your advice on

1) Whether we can restore the database from Management Studio GUI ?

2) If not, can you suggest a SQL Script for the backup ?


Thanking you in anticipation.

SQL2008 - Cannot Restore a new database from a full backup of a different one, database in use

I am trying to restore a brand new database from a copy of another one and am encountering an error message stating: System.Data.SqlClient.SqlError: The file <Backup source database file location> cannot be overwritten.  It is being used by database <Backup Source Database>. (Microsoft.SqlServer.Smo) I am running the Restore procedure with the REPLACE option and am wondering why it is stating that the source database is the database in use when I am trying to restore and overwrite a completely different database. This issue happens when running the replace both in C# using SMO and when manually restoring with SqlServer Management Studio Interesting note is, the original source database is created / deployed using a database project within VisualStudios 2010 and then deployed to SqlServer through VisualStudios. Any thoughts on why this is happening? Thanks in advance for any help!

Can't restore database backup file in my database ? using sql server 2005. please help

VERY IMPORTANT i am trying to restore database.bak in sql server 2005 (i know the database.bak was also generated in sql 2005 server) i am trying to restore back up database .bak into the new database i just created in sql server 2005 i have saved my database .bak into c drive and when i select database .bak "From Device", it doesn't get populated in the list below and i see nothing and it keeps on prompting a message "You must select a restore source" Here's the screen shot:   PLEASE HELP..it's really important (i tried restoring database in sql server 2008 and it was sucessful but i am facing this problem in sql server 2005 only)  

restore database failed

Hi everyone.   I had installed sql server 2008 on my local machine to develop a project.After i had done more than a half of that i had some problems with my computer so i had to format it.I backed up the database and i copied the file nomedatabase.bak. After formating and reinstalling the slq server 2008 r2 develope edition i would like to restore the database i had before but when i chose to restore the database  (i created a new database with the same name and than right click on the database -> tasks -> restore ->database  ) i get the following error.   TITLE: Microsoft SQL Server Management Studio ------------------------------ Restore failed for Server 'ALDUXO-PC\ALDUXO'. (Microsoft.SqlServer.SmoExtended) For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1447.4+((KJ_RTM).100213-0103+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Restore+Server&LinkId=20476 ------------------------------ ADDITIONAL INFORMATION: System.Data.SqlClient.SqlError: The backup set holds a backup of a database other than the existing 'aldux_test' database. (Microsoft.SqlServer.Smo) For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1447.4+((KJ_RTM).100213-0103+)&LinkI

how to restore msdb database on sql 2008 from sql 2005 backup?

Currently, I am unable to do it. It gives me the error than I cannot be restored because it was created by a different version of the server. What is the work-around? I hate scripting all my maintenance plans and alerts, there are tonns of themJulieShop

"The backup set holds a backup of a database other than existing database. Restore Database is term

I have a problem when i restore my .DAT_BAK file.  I am getting error like "The backup set holds a backup of a database other than existing database.  Restore Database is terminating abnormally".   I tried by using   RESTORE DATABASE <DATABASENAME> FROM DISK = 'D:\DATA\MYTEST.DAT_BAK' WITH MOVE 'VZAI_DATA' TO D:\PROGRAM FILES\..\MSSQL\TEST.MDF', MOVE 'VZAI_LOG' TO D:\PROGRAM FILES\..\MSSQL\TEST.LDF', REPLACE   And also i tried like   RESTORE DATABASE <DATABASENAME> FROM DISK = 'D:\DATA\MYTEST.DAT_BAK' WITH REPLACE   When i use like this,   RESTORE FILELISTONLY FROM DISK = 'D:\DATA\MYTEST.DAT_BAK'. I am able to get the output as LogicalName, PhysicalName, Type, FileGroupName, Size, etc.   Can i anyone please help me out?   Thanks in Advance, Anand Rajagopal

Error when running an SQL script to restore a database on SQL Server 2008 R2 Express

Hi, At work, I use SQL Server 2008 Express running on Windows XP Professional Service Pack 3. At home, I also use SQL Server 2008 Express running on Windows XP Professional Service Pack 3. Whenever I do work on the database at work, I usually restore the database at home (or vice versa) I have been using the following SQL scripts to back up the database and to restore the same database (at work or at home). BackupRealEstate.sql USE Master BACKUP DATABASE [RealEstate] TO DISK = N'F:\My Documents\My Database\RealEstate.bak' WITH NOFORMAT, INIT, NAME = N'RealEstate-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10 GO RestoreRealEstate.sql USE Master RESTORE DATABASE [RealEstate] FROM DISK = N'F:\My Documents\My Database\RealEstate.bak' WITH  FILE = 1, NOUNLOAD, REPLACE, STATS = 10 GO Everything worked fine until I replaced my 8yo home computer with a newer and faster one. My new home computer is running Windows 7 Home Premium and I use the latest SQL Server 2008 R2 Express. When I tried to run the above restore SQL script, I got the following error message: Msg 3101, Level 16, State 1, Line 2 Exclusive access could not be obtained because the database is in use. Msg 3013, Level 16, State 1, Line 2 RESTORE DATABASE is terminating abnormally. There was no other application/process using this database. Can someone please help me? Regards,

Backup/restore Failed don't exist timer jobs


According to John Ferringer, i'm moving this post from "SharePoint Products > SharePoint Products and Technologies Forums > SharePoint - Setup, Upgrade, Administration and Operation (pre-SharePoint 2010) > Backup/restore Failed don't exist timer jobs".

Hi Folks, i'm recieving this message when i try to make a site collection/farm/site backup "The backup/restore job failed because there is already another job scheduled. Delete the timer job from the Timer Job Definitions page, and then restart the backup/restore job.". I'm going to central administration/monitoring/timer jobs/check jobs status but i can not find anything.

My scenario:

- W2008 R2 EE

- MOSS 2010 EE

- MOPS 2010

- SQL Serve

sharepoint 3.0 service, database backup restore


I am using stsadm to run daily backup of the server, but would like to run hourly database backup, not sure if it works to restore database and log for sharepoint service 3.0, the db is on sql 2005 embedded edition. does any one know or has any suggestions to backup WSS3.0 hourly?

I tried the backup restore feature in the admin site, didn't get it work when last time the server crashes, so right now only use stsadm backup / restore.

Backup and restore of mdf database



I've got a following problem: I have a VB 2005 application that uses SQL Server 2005 Express as DB engine. This application has it's own database stored in mdf file, e.g. invoices.mdf with corresponding log file.

I'd like to give users opportunity to backup and restore this DB file from this application (there won't be a system administrator, only end-users). Unfortunatelly after I connect to this database (using user instance of SQL Server), I'm unable to read or copy it, despite the fact, that I close all connections. And I'm sure that all connections are closed.

Database files become accessible for reading after I close the whole application.

I've tried to detach this database using sp_detach_db prcedure, but it can't be done with database I'm connected to.

I will be grateful for any help.


Database deployment with Backup and Restore vs. Generate and Publish Scripts Wiz.


Could you please explain when is it better to deploy (publish) a database with Backup and Restore and when with the Generate and Publish Scripts Wizard?

As far as I understand Data-tier Applications in SQL Server 2008 R2 is a third option, isn't it? Are there more?

Thank you!

few sites are missing after taking backup and restore the content database


Hi All,

We have taken the backup of content database and restored it in the new server, after that attached the content database on sharepoint central admin, but few sites are missing after this. when checked the database server Number of records are matching in both the servers content database and also the data is matching, but still we are missing few sites. Do we need to do any specific change in sharepoint or database?

How to Specify Content Database for a Site Collection Restore from Backup


I have prepared code that first creates a new Content Database within a specified Web Application, then restores a Site Collection backup to that same Web Application.  Unfortunately, the Restore doesn't provide an option to select the Content Database that was just created.  So, is there something that I might do to ensure that the Site Collection gets restored to the Content Database of my choice, programmatically?  If not, is there something I can do to change the Content Database for the newly restored Site Collection?  All ideas would be appreciated.

Thank you,




i am restoring database and my restore terminate and failed with below error.

Processed 127940376 pages for database 'TST', file 'TSTDATA1' on file 13.
Processed 4416000 pages for database 'TST', file 'TSTDATA2' on file 13.
Processed 8421368 pages for database 'TST', file 'TSTDATA3' on file 13.
Processed 1156 pages for database 'TST', file 'TSTLOG1' on file 13.
Msg 3229, Level 16, State 2, Line 1
Request for device '\\.\Tape0' timed out.
Msg 3213, Level 16, State 1, Line 1
Unable to unload one or more tapes. See the error log for details.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

i try with different backup media but both the time receiving same error message.



Differential backup failed because the previous backup metadata for Database of SQL Server


I'm developing a VSS requestor that backs up Microsoft SQL Server, among other things. Full backups and restores work just fine. A differential backup always fails though, giving an error in the event log with Event ID 8197:

"Differential backup failed because the previous backup metadata for Database <dbname> of SQL Server instance <instance> is corrupted"

and the writer is in the state "VSS_WS_FAILED_AT_POST_SNAPSHOT" with error hr=0x800423f4

When my full backup runs, the differential_base_xxx fields in sys.databases are updated and correctly reflect the time that the full backup was taken.

The documentation I have read on the SqlServerWriter says that the metadata is recorded in the VSS event BackupComplete, which is definitely being called. During backup I see the writer state move from waiting for backup complete to stable.

I'm using SQL Server 2008 R2 on Windows 2008 R2. There are no other versions of SQL Server installed on that machine.

Can anyone suggest why this is happening?



Backup and Restore SQL Express 2008 database


Hi All,

How can backup and restore SQL Express 2008 database using c#.net

Thank you

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend