| | |
Back Up of SQL database in C#
Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
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
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
![]() |
Other Threads in the C# Forum
- Previous Thread: C# .Net 2005 version
- Next Thread: Beginner having trouble with nested if statements
| Thread Tools | Search this Thread |
.net access algorithm animation array bitmap box c# check checkbox client combobox control conversion csharp customactiondata database datagrid datagridview dataset datastructure date/time datetime datetimepicker degrees directrobot dll draganddrop drawing encryption enum excel file filename files form format formbox forms function gdi+ gis gtk hash image input install java label list mandelbrot math mouseclick mp3 mysql native operator outlook2003 packaging path photoshop picturebox pixelinversion pixelminversion post print process programming radians regex remoting richtextbox safari server sleep snooze socket sql statistics string table tables tcp text textbox thread time timer update usercontrol usercontrols validation visualstudio webbrowser webcam wfa wia winforms wpf xml





