Back Up of SQL database in C#

Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Dec 2007
Posts: 41
Reputation: IT_Techno is an unknown quantity at this point 
Solved Threads: 0
IT_Techno IT_Techno is offline Offline
Light Poster

Back Up of SQL database in C#

 
0
  #1
Apr 13th, 2008
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 SQLExpress .Is there any Better approach of achiving the
same?

Regards
IT_Techno
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Back Up of SQL database in C#

 
0
  #2
Apr 13th, 2008
If you are doing the backup and restore on the same SqlInstance, it is trivial.
Just use the SQL backup and restore syntax into an SqlCommand.

If going between SqlInstances, it can be more challenging. Databases using multiple file group require the target directories to already exist, although you can specify a MOVE to force the files into an existing directory of your choice. But first you need to find out what files are in the backup file. Then you have to synchronize logins SIDs because the SID will be different between SQL servers.

I am wrapping up a c# utility named SqlRestore that does all these things (and many many more), but I use SMO to figure out what is in the backup file before trying to restore it. I use SMO to perform the restore as well. SMO is (dot-net), and has many fetures that allow you to do all the things found in Studio.

So, the quick answer is, it doesn't matter what language you use to perform a backup & restore, it will eventually be done by SMO anyway (even Studio uses SMO under the covers). C# is as good as any to launch the task.

// Jerry
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC