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 »

Take database backup


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



Hey!
I was developing an application that perform replication programmatic from local client machine to main server. there i feel need of backup and restore database.
So below is the code for taking backup automatically


public Boolean BackUp(string ServerName, string Login, string Password)
{
try
{
SQLDMO._SQLServer srv = new SQLDMO.SQLServerClass();
//connect to the server
srv.Connect(ServerName, Login, Password);
//create a backup class instance
SQLDMO.Backup bak = new SQLDMO.BackupClass();
//set the backup device = files property ( easy way )
bak.Devices = bak.Files;
//set the files property to the File Name text box
bak.Files = "c:\\Fides-Backup.bak";
//set the database to the chosen database
bak.Database = "ReplicTest";
bak.Initialize = true; //OverWritten existing database
//perform the backup
bak.SQLBackup(srv);
//MessageBox.Show("Database successfully backed up.", "Backup Successfull");
return true;
}
catch (Exception err)
{
return false;
//MessageBox.Show(err.Message, "Error");
}
}


ReplicTest is my database name. so you have to change your database name
c:\\Fides-Backup.bak is path where backup will save

and don't forget to add reference of SQLDMO in your project, feel free to ask



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 Backup  .  

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: List files in any folder
Previous Resource: Database Restore
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