| | |
Back Up of SQL database in C#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
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 array asp.net barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum event eventhandlers excel file firefox form format forms function gdi+ grantorrevokepermissionthroughc#.net httpwebrequest image index input install java label libraries list listbox loop mandelbrot marshalbyrefobject math mouseclick movingimage mysql mysql.data.client operator path photoshop php picturebox pixelinversion post programming radians regex remoting resourcefile richtextbox server sleep socket sql statistics stream string study system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf wpfc# xml





