C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

Database Restore


Posted Date: 20 Oct 2009    Resource Type: Code Snippets    Category: C# Syntax
Author: nisarMember Level: Gold    
Rating: 1 out of 5Points: 6



In my last Code snippet i place the code how we can take database backup programatically, this code snippet will show how to restore database


public void Restore(string ServerName, string Login, string Password)
{
try
{

//create an instance of a server class
SQLDMO._SQLServer srv = new SQLDMO.SQLServerClass();
//connect to the server
srv.Connect(ServerName, Login, Password);
//create a restore class instance
SQLDMO.Restore res = new SQLDMO.RestoreClass();
//set the backup device = files property ( easy way )
res.Devices = res.Files;
//set the files property to the File Name text box
res.Files = "c:\\Fides-Backup.bak";
//set the database to the chosen database
res.Database = "ReplicTest";
// Restore the database
res.ReplaceDatabase = true;
res.SQLRestore(srv);
//MessageBox.Show("Database restored successfully.", "Restore Successful");

}
catch (Exception err)
{

//MessageBox.Show(err.Message, "Error");
}
}
[\code]

ReplicTest is the database name where database will restore
c:\\Fides-Backup.bak is a path where your database file is exist
Add SQLDMO reference in you application to make the code usable



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Database Restore  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Take database backup
Previous Resource: Create HTML E-mails with embedded image
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use