I'm working on a small project (not production) where I'm needing to store enough data that something like a CSV would be inefficient to process and an SQL/MySQL server would be too much. Does .Net have any way to efficiently store several entries of data with the ability to query without having to manage and connect to a server rather loading and processing a single file.
4 Answers
There are a few alternatives, in no particular order:
- All versions of (paid?) visual studio come with SQL Server Express installed. You can use that.
- (Ugh) XML files
- SQL Server CE (basically, local SQL via file)
- SQLite
More ideas here: https://stackoverflow.com/questions/3639846/what-is-a-good-embedded-database-to-use-with-c
-
I really want something that is totally self contained in a single executable, no DLLs and no third party software. Are any of the above, except XML, able to fit these needs?– DavidJul 2, 2013 at 19:38
-
-
Well I guess the most important part is no third party *services such as MSSQL/MySQL would #3 or #4 fit that– DavidJul 2, 2013 at 19:42
-
I don't remember if SQL CE has a separate runtime or not. SQLite doesn't, but it can be a little tricky to set up with a .NET project. Jul 2, 2013 at 19:50
-
3I would add that LocalDB is an option. See this answer: stackoverflow.com/questions/9655362/…– AndyJul 2, 2013 at 20:59
In addition to the options Sklivvz offered, don't be afraid to venture outside of the SQL realm and use an embedded object-oriented database engine, such as Sterling or DB4O.
They offer the advantages of being small and file-based, embeddable into your application, but are also very fast and easy to program to.
SQLite would be your best option.
As written on their site:
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
Seems really what you're looking for!
There's even a Chocolatey package if you're too lazy to download and install it yourself!
ADO.NET can serialize to XML and has almost all of the functionality of an RDBMS. (Well, the cheap ones, anyway.)
I know it's "Old" and looked down on, now, but ADO.NET works really well for exactly what you're describing. It even does a pretty decent job of tracking non-committed changes.
It may be "Old," but it's certainly not "Busted." It's got a fairly heavy memory footprint, though, so your call on that. 4000 records won't be an issue.
-
-
@David - It means that the entirety of the dataset would be held in memory, and not just the records you return from a query. If you had a database of 4 million records, holding it all in an ADO.NET dataset would be a serious draw on resources, whereas a "Real" RDBMS would hold it on a disk until you queried a subset of them. 4000 records is a small sneeze in memory usage, so I wouldn't worry about it. Jul 2, 2013 at 23:19
-
+1, I think this is the best option, for this requirements even something small as SQLlite seems to be much effort. Jul 4, 2013 at 10:33
List<foo>
)