1

What is the best or preferred way to store data for a .NET desktop application? I know this could depend on how I will be using the application, but I'm just looking for a simple and easy way to store data for .NET applications.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Kory
  • 71
  • 1
  • 4
  • 1
    Related (and possible dupes): http://stackoverflow.com/questions/2709006/ways-to-store-data-in-net, http://stackoverflow.com/questions/1419336/alternatives-of-persisting-data-using-c, http://stackoverflow.com/questions/1931015/looking-for-ideas-on-storage-of-data-on-local-disk, http://stackoverflow.com/questions/657220/which-is-the-best-data-access-framework-approach-for-c-and-net, http://stackoverflow.com/questions/1941928/best-way-to-store-data-locally-in-net-c, http://stackoverflow.com/questions/2172227/where-to-store-configs-for-simple-net-application – Aaronaught May 09 '10 at 21:53

4 Answers4

1

Use isolated storage.

Tom Cabanski
  • 7,828
  • 2
  • 22
  • 25
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Gaffi Aug 22 '12 at 13:26
  • Well, not exactly legal to copy copyrighted material into another web page. Besides, it is the Microsoft docs that are linked to here (and the link is still good even more than 2 years later) – Tom Cabanski Aug 23 '12 at 14:11
  • Understood, but it is still more helpful to at least describe some of the processes (rather than copy the code outright) than just posting a link. Also, while the link may be good today, there's no guarantee it will forever be. For the record, the only reason I commented on this post was because I was prompted to by the low-quality review tool (due to its link-only content). See [this Meta post](http://meta.stackexchange.com/a/143667/179372) for more details. – Gaffi Aug 23 '12 at 14:25
  • @Tom: actually, copying small portions of copyrighted works as part of a larger composition is generally considered to be fair use - and thus legal - in the US. In this particular case, you might be hard put to find a relevant quote, since the asker left his problem statement fairly vague... But for future reference. (And I've certainly come across a ton of broken MSDN links in the past. Sad, but true.) – Shog9 Aug 23 '12 at 16:08
1

Give an OODB a try. You can use db4o.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Vagaus
  • 4,174
  • 20
  • 31
0

It kind of depends on the nature of the data, and your "target audience".

If this is a lot of data, maybe file storage is not something you want, and you want to look at a database-like storage.

If it is some minimal set of user choices, that are often read, and limited written, the registry is a good choice.

If you are in an enterprise environment, you also need to be aware on limitations (policies) that prevent you from storing a lot of data in the user profile.

If you want the user be able to select the files, allow the user to store the data in My Documents, but get the exact location from the user. Technical data is better stored in the "Local Application data" or "Isolated Storage".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
GvS
  • 52,015
  • 16
  • 101
  • 139
  • For the time being, I want to create simple applications such as a journal or calendar with a todo list and these would be for personal usage only. I like the idea of using a server less database for this. There are also applications I have in mind that would have some drop down fields, however I would like to be able to edit the data in the drop down. Would you suggest the registry for something like this? Do you know of any good tutorials that use c# and SQL Server Compact? What other server less databases are there or can you suggest? Thanks – Kory May 10 '10 at 01:40
0

You may find that NHibernate suits your needs. NHibernate is an ORM that basically persists your objects in a database (which can be nearly any flavor, but SQL Server Compact Edition would be an appropriate choice for a stand-alone desktop application) and reconstitutes them for you.

I personally do not like or use ORMs, but they are a well-established and popular technology, and because they opaquely encapsulate the underlying database/storage mechanism, they make this decision much less important to an application developer. You could start with NHibernate on top of SQL Server CE, and if SqlCe doesn't work out for some reason you can switch databases without changing the rest of your program.

You don't have to use NHibernate, of course, and the ADO.NET classes provide essentially the same database independence.

MusiGenesis
  • 74,184
  • 40
  • 190
  • 334