1

I'm trying to implement the export functionality for my database application. I'm using C# and have the SQlite wrapper for C# that I'm using. Pardon my ignorance of database concepts/common usage, this is my first database application.

Export : Easily enough, the SQLite databases are stored in a single s3db file. So, to export, I simply need to copy that file using System.IO.File.Copy? Is that the best way to do this? Lastly, with export, do I need to close all database connections before copying the file? Again, best practices for this situation would be a great help... I'm unsure as to a few things in this situation. For example...

What if the database is huge and the copy takes a while? The user could start a export, then immediately go and try to insert something into the database, which would obviously be an issue. Should I lock the program while copying?

As always, thank you for any assistance.

1
  • 1
    Now that I know copying the file is the correct way to go, how do I create a modal windows form to display a progress bar? Commented Dec 18, 2010 at 5:07

3 Answers 3

1

I did similar functionality for SQL Server CE, which is very similar to sqlite in concept. The safest way to handle it is how you suggested: Close all database connections and prevent the user from opening anymore (I handled this with a modal window over the entire application that showed progress of the backup). Again, I haven't done it with sqlite per se, but with SQL Server CE, it was a simple file copy.

To make a window modal over the entire application for a WinForms app, simply use MessageBox.Show(), and do not specify an owner.

Sign up to request clarification or add additional context in comments.

2 Comments

MessageBox.Show() where? I have just created a Windows Form to show progress, and was planning on making it immovable and unclosable. Do I call that in my ProgressForm form code? Thanks for the contribution!
Sorry, I wasn't thinking straight. To show a form modal to the whole app, create an instance of that form, and instead of calling Show(), call ShowDialog(), but the same rule applies as far as not passing in an owner to make it modal to the entire application. It's probably possible to make the dialog immovable, but that would irritate me as a user if it were done. You can make it uncloseable by taking the control box away and canceling any closing events the form fires. Though nothing will stop a user from forcefully shutting down the entire application.
0

The advantage of copying the file is simply that the alternative, recreating the database and inserting the records, will assuredly take a lot more time. You should definitely lock that operation if your app allows changes to either the source or the export.

Comments

0

Copying is the simplest way, but I'm not sure it's the best way. Aside from having to make sure you're locking the the file during copying, you might want to dump the data into a format that's a bit more portable than just the binary representation of the specific version of SQLite you're using.

Dumping all data into a file is just as easy as copying.

See, for example: "Converting An Entire Database To An ASCII Text File" in this page.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.