8

If this question seems common to you, I apologise, I did a quick search around this site and a few google searches and could not find a satisfying answer.

My question is this;

I have only been a software developer for 3-4 years now. This may seem like a time long enough to answer this question myself however in all my time, I have never had to develop software where the main body of data-storage is not required to be in an on-line database. This time however, my latest development requires only for its data to be stored only to disk.

The actual data itself is light-weight. In-code the main asset will be a class with only a few, string based properties on it which must be persisted. My initial thoughts are on simple serialisation. On application close new assets are simply serialised and stored on disk as a file. I also though maybe for backup purposes (or if it is somehow a better option to a serialised class) an XML file would be appropriate.

I cannot think of any distinct disadvantages of either of these approaches, it is this fact which causes me to ask this question publicly. In my experience, there is rarely a solution to a problem which does not have it's downsides.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user407356
  • 284
  • 5
  • 18

4 Answers4

3

Serialization (binary or XML) is appropriate for a small amount of data. The problem with this approach is when you get large amounts of data (that you may need to query).

If you are on a windows platform and in need of a proper database, you can use the embedded database engine that comes with windows - ESENT. It is the backing store of Exchange and RavenDB.

Here are the .NET wrapper libraries for it.

ManagedEsent provides managed access to ESENT, the embeddable database engine native to Windows. ManagedEsent uses the esent.dll that is part of Microsoft Windows so there are no extra unmanaged binaries to download and install.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Oded
  • 489,969
  • 99
  • 883
  • 1,009
1

The most lightweight solution, is of course to use XML and serialization. The main advantage of that is that it is very easy, requiring little code, and is easily editable using a text editor. The other advantage of this is being able to have multiple files, and they will be easy to transfer from PC to PC.

Here is a nice tutorial on XML serialization.

However, if your application is going to be reading, writing, and changing the data a lot, and there is only one source of data, it would be better to use a light-weight database. Many people like SQLite, while I personally prefer Firebird.

See this question for using SQLite with C#, and see here for information for using Firebird with .net.

Community
  • 1
  • 1
Vincent McNabb
  • 33,327
  • 7
  • 31
  • 53
0

Another embedded database option is Sql Server Compact Edition. The latest version of this is v4 and it seems to be much improved over previous versions.

It's functionally equivalent to using an XML file, or an access database, or even a plain old text file, in that you don't need to have a Sql Server service running or install anything special on the machine that your application runs on.

Rob
  • 45,296
  • 24
  • 122
  • 150
  • as time passses: "As of February 2013 SQL Server Compact Edition had been deprecated; no new versions or updates are planned, although Microsoft will continue to support until July 2021". So pretty soon it will be unsupported. – Luuk Jun 03 '21 at 06:10
0

I've been using Sqlite in a project and it works very well and it's easy to use too, one thing to keep it mind when using Sqlite though is that it's designed to be used in a single user environment, so if you use it as the database for the backend of a website for instance you're likely to find that it'll struggle under the slightest of load..

Check out this link for the C# wrapper: http://sqlite.phxsoftware.com/

I also use NHibernate and NHibernate.Linq to interact with the data, you can get a build of both which are compatible here: http://www.dennisdoomen.net/2009/07/nhibernate-210-ga-with-linq-and-fluent.html

NHibernate.Linq allows you to use those nice Linq query syntax on your Sqlite db:

var onePiece = from s in session.Linq() where s.Name == "One Piece" select s;

theburningmonk
  • 15,701
  • 14
  • 61
  • 104