restoring database using SQLDMO

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mohammed Abdel-Razzak

    restoring database using SQLDMO

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

    thanks
    Mohammed
  • Damon Tivel [MSFT]

    #2
    Re: restoring database using SQLDMO

    Hi, Mohammed.

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




    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.SQLServe r 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_R ESTORE_TYPE.SQL DMORestore_Data base;
    restore.Databas e = "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.FileNum ber = 1;

    // Optional. ReplaceDatabase property ensures that any
    existing copy
    // of the database is overwritten.
    restore.Replace Database = 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.SQLRest ore(server);
    }
    catch (Exception ex)
    {
    // Handle the exception.
    }

    BTW, there's also a SQL Server programming newsgroup
    (microsoft.publ ic.sqlserver.pr ogramming).

    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.

    "Mohammed Abdel-Razzak" <anonymous@disc ussions.microso ft.com> wrote in
    message news:1e3c601c45 526$8ee950f0$a5 01280a@phx.gbl. ..[color=blue]
    > Dear sirs
    > I`ve used SQLDMO to make a backup to my database
    > How can I use it to restore database?
    >
    > thanks
    > Mohammed[/color]


    Comment

    Working...