473,770 Members | 7,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6341
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.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" <an*******@disc ussions.microso ft.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
5245
by: David | last post by:
Does anyone know where I can find example code for VB.NET that I can use to create an application that attaches and detaches databases to MSDE using osql scipts. (I think SQL-DMO is typically used) Thanks in advance
1
1524
by: Sherif | last post by:
I'm making an application using csharp to connect to a database made by MSSql Server and i've already done backup for the database from the csharp and i need now to know how can i restore the database back by using csharp code.
1
1944
by: Cui | last post by:
Hello, I make an application in ASP.NET (using VB.NET and some web services). For my needs, I use also the SQL DMO library (with the SQL DMO.interop assembly) and the Microsoft Web UI controls (in order to have the tree view, multi bar controls). When I make the compilation and the execution, I obtain then the next error: "
2
1739
by: DKC | last post by:
Hi All, Is there any way wherein I can get a list of database servers on my local network. Any help appreciated. I am using VB.NET 2003 Thanks DKC
3
7030
by: Zack Sessions | last post by:
I am using VB.NET 2003. I found the following sample code here in an article: Dim oSQLServerDMOApp As New SQLDMO.Application Dim i As Integer Dim namX As SQLDMO.NameList namX = oSQLServerDMOApp.ListAvailableSQLServers For i = 1 To namX.Count
0
2024
by: Pankaj Jain | last post by:
Hi , Can any one tell me the Optimized & fastest way of taking backup & restoring my database that is in SQL Server through C# code. Currently I am using SQLDMO .Is there any Better approach of achiving the same? Regards Pankaj Jain
5
6567
by: Troels Arvin | last post by:
Hello, Every so often, I'm asked to help people recover data from tables that were either dropped or where to much data was DELETEed. The complications related to restoring data are a problem. The SAS users are laughing because they can (to a certain extend) easily go back to an earlier SAS table by simply starting dsm. Of course, a flat file table is different than a relational table; but still, the trouble related to restoring DB2...
1
1350
by: truptikalani | last post by:
i want to restore SQL server databse from a file which is created by taking backup of database through coding using SQLDMO object in visual studio 2005. i wrote code for restore using SQLDMO object but it is giving error as no exclusive access to database. database is used by other application. what can i do now? i think i could try for lock but how? could u plz help me?
0
836
by: dvp10 | last post by:
I ve developed a database in SQL server2005 I want to backup that database using C#... For this i m using SQLDMO object.. i ve successfully connected to database but i m getting an exception when i try to create an object of SQLDMO.BackupDevice() what is the problem?
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.