restoring database using SQLDMO

  • Thread starter Thread starter Mohammed Abdel-Razzak
  • Start date Start date
M

Mohammed Abdel-Razzak

Dear sirs
I`ve used SQLDMO to make a backup to my database
How can I use it to restore database?

thanks
Mohammed
 
Hi, Mohammed.

The following MSDN link contains a SQLDMO restore database code sample:


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sqldmo/dmoref_ex02_8j8x.asp

Assuming that you have a reference set to the "Microsoft SQLDMO Object
Library" (sqldmo.dll) library, the following code is a straight conversion
to C#:

try
{
SQLDMO.SQLServer server = null;

// Connect to your server here.

// Create a Restore object and set action and target
database properties.
SQLDMO.Restore restore = new SQLDMO.Restore();
restore.Action =
SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
restore.Database = "Northwind";

// Example illustrates restore from a striped backup. Two
source devices
// are specified. The full database backup is indicated as
the first
// backup set by using the FileNumber property. Note: Device
creation is
// not illustrated in this example.
restore.Devices = "[NorthDev1],[NorthDev2]";
restore.FileNumber = 1;

// Optional. ReplaceDatabase property ensures that any
existing copy
// of the database is overwritten.
restore.ReplaceDatabase = true;

// Call SQLRestore method to perform the restore. In a
production
// environment, consider wrapping the method call with a
wait pointer
// or use Restore object events to provide feedback to the
user.
//
// Note: Create and connect of SQLServer object used is not
// illustrated in this example.
restore.SQLRestore(server);
}
catch (Exception ex)
{
// Handle the exception.
}

BTW, there's also a SQL Server programming newsgroup
(microsoft.public.sqlserver.programming).

Hope that helps,

Damon
Visual C# IDE

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top