Thomas Huber
Thomas Huber

Reputation: 1302

How to restore a SQLite database while an open connection exists?

I am writing a plugin for a C# application which uses SQLite database. The initial database is stored in database.db.default. At any point during runtime the user should be able to reset the database to the default content.

Since the application has always an open connection to the database I can not just copy database.db.default to database.db.

Whether or not it is a good idea to always hold an open connection is a total different question. But that is just how it is since it is not my call to change that part of the application.

Is there any way I am able to restore database.db.default into database.db using C# and .NET 3.0?

I appreciate any kind of help ...

Upvotes: 3

Views: 1949

Answers (2)

Jay
Jay

Reputation: 14471

If you can't do a file copy to restore the database then do the restore the hard way. Attach the backup database, delete all the data in the main database, then insert the data from the backup database.

Upvotes: 1

Tim Destan
Tim Destan

Reputation: 2028

I'm probably missing something here, but can't you just close your connection and reopen it after the copy?

Upvotes: 0

Related Questions