Best way to use NDatabase in a desktop application?

Dec 12, 2014 at 8:29 PM
Edited Dec 12, 2014 at 8:30 PM
I'm looking at using NDatabase in a desktop application, but I'm not sure the best way to manage the NDatabase IOdb object.

In my case, the database will be used for document storage (as opposed to something more real-time). A user will open documents from the database, edit them in the application, and then save them back to the database.

It seems like I have two options:
  • Create a single IOdb instance for the entire session, closing it only when the user exits.
  • Create an IOdb instance for each transaction (loading a document, saving a document, etc.).
What's the best option in terms of performance and safety? It seems like the first would be more performant, but the second would allow me to keep transactions separate and ensure the database is properly closed (in case of application crashes).
Dec 14, 2014 at 3:59 PM
I would recommend to start with safest option, so open connection to file only when you really need, and close as quickly as that possible. Once you will see how it's working, then you will be able to see if there are any performance issue.

I would focus on some improvements (holding connection for longer time, some own caching/improvements) only if above makes performance issues for you.