views:

267

answers:

2

Is it possible to take Backup of SQL Server Compact database (i.e. *.sdf) and Restore the same.

+3  A: 

Just copy the file. Done.

Quote from Maintaining Databases:

Because SQL Server Compact 3.5 is a file-based database system, you can accomplish many common database tasks such as backing up, restoring, and deleting a database by using the file system APIs.

To back up a database, close all connections to the database, and then copy the .sdf file. To restore a database, copy the .sdf file back to its regular working location. These operations work even if the database is set up for replication. To drop a database, delete the .sdf database file.

AngryHacker
No programmatically we need to take backup like,SqlCeCommand cmd = new SqlCeCommand(); cmd.Connection = conn; cmd.CommandText = @"BACKUP DATABASE [D:\\CompactDatabases\\Northwind.sdf] TO DISK = 'C:\\Test\\DB.bak'"; cmd.CommandType = CommandType.Text;int i=cmd.ExecuteNonQuery(); but it is throwing exception as below : There was an error parsing the query. [ Token line number = 1,Token line offset = 1,Token in error = BACKUP ] Then how take the backup programmatically?
team-ferrari22
Programmatically? Sure. File.Copy("mydb.sdf", mybackup.sdf");
ctacke
A: 

I write the compact SQL database out to an XML file using LINQ to SQL and read it back in to restore it.

Mark W
Thank you for your reply.Do you think we can restore backup taken from SQL Server database in to SQL Server Compact database.
team-ferrari22