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


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