Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all.

i am creating an application for a shop with sqlserver 2008 and c#. for this shop i want sometimes for example in every week user can backup his database information to a file in computer hard disk and he can restore them. i can use sql command's to backup database to hard disk but my problem is when i want to restore that file. in fact i do not know when i must restore backup file. please say me when i must use restore command. and what condition must be in there?

thank you all;
Posted

1 solution

This explains how to do it from C#: Backing up an SQL Database in C#[^] and may help.

But under normal circumstances you should never use Restore: once your backup system is in place and tested, you would only need it if there has been a problem and the "live" database is corrupted or missing - because a database restore operation is designed to put a database back to it's last known good state: the point at which you backed it up. To do this, it throws away the existing data and replaces it with the data as it was when the backup was taken. For this reason, you should take regular (and frequent) backups: Daily is good, but weekly may be possible - it depends how much data you can afford to lose or have to reenter.

By preference, operate a Grandfather / Father / Son backup scheme as a minimum: if the son is faulty, you can use the Father, and so on. And store backups away from the primary they were copied from, preferably off site!

The one time you should hope you ever have to do a restore is to test your backups, and make sure they are still working: and that is worth doing deliberately a couple of times a year, just to be sure! (Preferably immediately after a extra special set of really good backups have just been done!)
 
Share this answer
 
Comments
_Starbug_ 19-Mar-14 12:34pm    
thank you my friend(OriginalGriff). i learned good things from you. one question that appear in my mind is that what i must do if my database or my customer database was corrupted and need to restore the backup file.what i must do in restore operation? and what is corrupted? database or another thing in application? thank you
OriginalGriff 19-Mar-14 12:46pm    
If you have a look at the link, it shows how to do a matching backup and restore, so if you use that code you should be fine.

As to "what is corrupted? database or another thing in application?" that is a question without an answer! It's certainly possible to corrupt a database through hardware problems (HDD failure is always a good laugh), or through a bug in SQL Server (though that's pretty rare these days), or through user input (Arrgh! No! Stooooooopppppppp! ... Bugger.), or through application problems - including the very wonderful "forgetting to add a while clause" when issuing an UPDATE:
UPDATE tabUsers SET username='Fred'
will set every user to the same name, and cause copious swearing...

So basically, "what can corrupt a database"? Everything. :sigh:
That's why I backup, often, and test the backups regularly as well...
_Starbug_ 19-Mar-14 12:57pm    
thanks alot
OriginalGriff 19-Mar-14 12:58pm    
You're welcome!
VICK 20-Mar-14 6:50am    
Fantastic answer to the question and the comments as well.

My 5+ :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900