What options are available for local state persistence in .Net
I'm 开发者_C百科looking for good options for persisting local state of an application (created in .Net / C#.)
I've considered rolling my own solution, or using a simple local database such as Sqllite, however I thought I'd ask the SO community what options are available.
The application I'm working on exists on a Kiosk, and I will need to maintain local state in case of accidental shutdown and other similar exceptions.
What do you recommend?
Update
Well, after further review I decided to use SQLite with DbLinq, the main alternative contender was SQL Server Compact edition, but there are several factors which I found important, which placed SQLite above SQLCE.
Notably.
- The API provided by SQLCE (IMO) wasn't as rich as the ones provided by both SQLite.net or DbLinq.
- SQLCE runtime performance wasn't as good as SQLite.
- SQLite being open-source is a useful factor.
Why I didn't use Properties.Settings or app.config?
For my use case I needed something like a (easily) query-able event log (I need to allow auditing of credit transactions.) The primary state value I was addressing here was available credit on a kiosk. So to restore my state variables at application start up, I can query the log for the last entry and get the required values from there.
When you only need to store a value and retrieve it Properties.Settings or app.config are perfectly adequate places to do this.
I would recommend XmlSerializer
or BinaryFormatter
, you can look them both on SO or google.
Your choice will depend on few preferences such as size of dataset or ability to serialize it quickly.
And both are really quick way IF YOU NEED whole app state saved in one go.
However, if you need to save app state part by part, as changes occur, you'll be better of with some kind of a database, http://www.sqlite.org/ for example.
http://www.jonasjohn.de/snippets/csharp/xmlserializer-example.htm
http://www.jpreece.com/csharp/serialization-tutorial/
SQLite is definitely a good option, it's lighter than a full blown database, and it's ACID compliant in case something goes terribly wrong.
The only requirement here is that you have one concurrent user for the database.
Can you use the app.config or Properties.Settings
?
You can use Settings in VS. For your case, you need user-scope settings that store user preferences.
You can use SQL Server CE 4.0 instead of SQLite. Store data in one file and you can use the Entity Framework Code-First.
精彩评论