Reputation: 1616
In a webapp I am building, I have a requirement in which I need to backup and restore around 10-15 tables from a SQL Server database.
My solution..
-Backup: For each table, Fill a dataset , serialize that to a file
-Restore: Deserialize the file into a dataset and use SQLBulkCopy
Is this the best was to achieve my goal?
Upvotes: 0
Views: 1210
Reputation: 5922
Could you not simply move/copy the data back and forth between (backup) database tables? Why deal with files?
IMO a database is almost certainly the best place to store backup data. It could be in the same database (Customer >> CustomersBak) or you could have a small database you copy data across to.
Two issues you might have with restoring the data back:
1) as sambo mentioned, identity columns.
2) foreign key constraints with other tables that might get out of synch and prevent you from refreshing the original tables
Upvotes: 2
Reputation: 131192
You need to make sure you consider the following.
Upvotes: 1
Reputation: 300797
You can use SQLSMO to backup/restore an entire SQL Server database. This article by John Papa covers it in detail.
You can also programmatically run BACKUP/RESTORE commands against the DB.
Upvotes: 4