469,133 Members | 1,209 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,133 developers. It's quick & easy.

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
Nov 16 '05 #1
1 6006
Hi, Mohammed.

The following MSDN link contains a SQLDMO restore database code sample:
http://msdn.microsoft.com/library/de..._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.

"Mohammed Abdel-Razzak" <an*******@discussions.microsoft.com> wrote in
message news:1e*****************************@phx.gbl...
Dear sirs
I`ve used SQLDMO to make a backup to my database
How can I use it to restore database?

thanks
Mohammed

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sherif | last post: by
reply views Thread by Pankaj Jain | last post: by
5 posts views Thread by Troels Arvin | last post: by
reply views Thread by dvp10 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.