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

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

Backup and restore of mdf database

Posted By:      Posted Date: October 07, 2010    Points: 0   Category :Sql Server


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.


View Complete Post

More Related Resource Links

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)  

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

Restore Database Backup using SQL Script


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

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.

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,


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.

Backup and Restore SQL Express 2008 database


Hi All,

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

Thank you


BACKUP WITH CHECKSUM against an encrypted database - restore fails


I have five databases sitting on a new SQL 2008 R2 server.  The databases originated on SQL Server 7, went through both a SQL 2000 and a SQL 2005 upgrade, and last month were migrated to this new SQL 2008 server.  All five databases are in SQL 2005 compatibility mode.  All five databases are using SQL 2008's full database encryption.

Over the weekend, I changed the page verification of these databases from "torn page" to "checksum".  Nightly full backups were completed on Sunday night, and successfully restored to our reporting and hot-standby servers.  Yesterday, I added the WITH CHECKSUM keyword to the backup jobs.  Nightly full backups ran last night, completed successfully.  The restores of those same backups to reporting and standby FAILED, with several assertion failure messages.

Today, I created a brand new database, in SQL 2008 compatibility mode and "checksum" page verification.  BACKUP WITH CHECKSUM produces a restorable backup.  I then enabled encryption on that database, and did the same BACKUP WITH CHECKSUM operation.  The resulting backup cannot be restored, NOT EVEN on the same server.  The restore appears to complete, giving the normal output stating how many pages it processed, but the "recovery" portion of the restore throws an exception.

Restore of database backup done by script failed



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

Unable to restore database backup.



I am trying to restore a SQL Server 2005 database backup file.The size of the database backup is 5.51 GB. I specify the  source as a device and then provide the path of the .bak file and press OK i get the error as follows





TITLE: Microsoft SQL Server Management Studio

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)


The media family on device 'G:\ITWeb DB Bkup\DB Bkup\New Bkup\WSS_Content_ITWEB.bak' is incorrectly formed. SQL Server cannot process this media family.
RESTORE HEADERONLY is terminating abnormally. (Microsoft SQL Server, Error: 3241)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.1399&EvtSrc=MSSQLServer&EvtID=3241&LinkId=20476



SQL Server Backup and Restore (video)

Restore your full backup, then run a few queries before you keep restoring transaction logs. Brent shows how to use the Standby option for restores.

In this five minute video, Brent demonstrates how to do it by creating a database, populating data, and then showing what disaster recovery is like by doing RESTORE WITH STANDBY.

SMO Backup and Restore Help

Hello Friends, I am new to SMO, Till now I have only worked with Selct,Insert/update Queries.. Now I want to Implement some backup and restore feature for my application. I looked at some documents of SMO and found it is possible using SMO. First of all I will explain my situation. My application wants to store data belongs to different companies(which is maintained with in application) in to single database server, Sql server 2008. I am planning to use Partition Scheme function and create filegroup for each company. Advantage here is, taking backup of each company will be easy. I am generating primary key for each table without taking into consideration of companies. In other words Particular table's ID 1,2 belongs to Company A, 3 Belongs to Company B and 5 belongs to Company A... But these data will be split in to Different filegroups using Company ID.(horizontal partitioning) Ok... Now the Problem.. My backup for a particular company was taken successfully. Now I want Restore function. When I am trying to restore this backup to somewhere else. Target database may or may not contain Companies installed. When Restoring Will there be any Primary key Violation? I know one solution is to generate primary key by taking into consideration Company Id. But this will cause a complete rewriting of code, as it contains lot of edit/delete queries.  I want to know, whether the

What happened to the backup and restore classes in namespace Microsoft.SqlServer.Management.Smo vers

I do not see these two classes in version 10 of this namespace and I am not finding any documentation explaining what happened to them.
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