3

Basically I have a windows form C# program that uses a SQL Server Express database to store data entered by the users. I want to add the ability for the user to be able to backup their database and then load a backup or another database into the programs database.

If someone could point me in the right direction like an article or tutorial that would be great, because I have hit a dead end.

Thanks

1
  • There are tons of websites that explain how to do this. It would be far easier on yourself and your users, if you use the tools that already exists, instead of failing to implement this sort of thing. All you would have to do honestly in the case of a express database is copy the database file, and then just write documentation, on how to restore that file. Dec 14, 2011 at 20:15

3 Answers 3

3

You have a few options to do this:

  1. On the server directly call BACKUP DATABASE, RESTORE DATABASE commands.

  2. Use SMO (SQL Server Management Objects) to perform the backup restore operations programatically. (Specifically this sample)

  3. Use some third party utility/library.

0
1

You may want to look at using this suggestion:

http://codeasp.net/articles/sql-server/118/backup-your-database-using-an-sql-command-export-to-bak

0

The nice thing about SQL Server is that you can do more or less everything with SQL (T-SQL or some variation thereof) - this is nice because it means that it is relatively easy to do most things without having to worry about (for example) the availability of SMO and further in a reasonably generic fashion.

The second nice thing is that if you run a command in SQL Server Management Studio (a version of which can be downloaded for SQL Server Express) it will, more often than not (and certainly in the case of Backup and Restore), offer to let you save the the script to a file instead of executing it.

So, it would be straightforward for you to use SQL Server Management Studio to determine the structure of SQL based backu and resotre commands and from there to integrate those into your application.

There is, however, a "gotcha" - SQL server will only save backups to/restore backups from a drive that is visible to the machine & service account upon which the SQL Server instance is running, almost certainly not an issue if your application is running on the same machine as the user but potentially a problem if they are not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.