Embedded database for C# supporting multiple connections - c#

Is it possible to have an embedded database as a file shared on a network disk and used simultaneously by multiple users (to both read and write)?
Slowness is not an issue, but no database software should have to be installed. Is Microsoft SQL Server Compact appropriate for such a purpose?

I found this page on the msdn which suggests that version 3.5 and above of MS SQL Server Compact should be o.k. in this scenario.
To support multiple applications that
access the same database at the same
time, SQL Server Compact 3.5 provides
multiuser support. Multiuser support
enables multiple users of a database
to synchronize data without having to
disconnect the database before they
use merge replication or remote data
access (RDA). For more information
about multiuser synchronization, see
Multiuser Access and RDA and Multiuser
Access and Synchronization.
However I, personally, have no experience with this so could not say for sure if this will definitely work.

Have you tried VistaDB?
I believe it should meet your requirements.

SQLIte for .NET should work for you!
SQLite is a small C library that
implements a self-contained,
embeddable, zero-configuration SQL
database engine. Features include:
Transactions are atomic, consistent, isolated, and durable (ACID) even
after system crashes and power
failures. Zero-configuration - no
setup or administration needed.
Implements most of SQL92. (Features not supported)
A complete database is stored in a single disk file.
Database files can be freely shared between machines with different byte
orders.
Supports databases up to 2 terabytes (241 bytes) in size.
Sizes of strings and BLOBs limited only by available memory.
Small code footprint: less than 30K lines of C code, less than 250KB code
space (gcc on i486)
Faster than popular client/server database engines for most common
operations.
Simple, easy to use API.
TCL bindings included. Bindings for many other languages available
separately.
Well-commented source code with over 95% test coverage.
Self-contained: no external dependencies.
Sources are in the public domain. Use for any purpose.

Related

Does windows have some inbuilt database engine?

So far, in my applications, I stored all my data via serialization, so I never really needed anything else. But now I am working with more complicated data and I need more than a simple file to store them. Is there some inbuilt storage engine in Windows I can use, which will allow me to pull and edit data with SQL queries? (Since I doubt the user will be willing to install and configure standalone MySQL server just for my application and I don't really want to use 3rd party solutions)
And if there is, how can I access such database engine?
Yes, Windows does have an embedded database engine, which has been there since Windows 2000. It is called Esent.
There is a project called Managed Esent to expose the features of Esent to managed code. There is a NuGet package for it.
I do not know whether it fits your exact need of updates via SQL queries but it does boast a number of features:
ACID transactions with savepoints, lazy commits, and robust crash recovery.
Snapshot isolation.
Highly concurrent database access.
Flexible meta-data (tens of thousands of columns, tables, and indexes are possible).
Indexing support for integer, floating point, ASCII, Unicode, and binary columns.
Update
I have since had some experience with Esent in C# via the nuget package. It does NOT have SQL query capabilities. There is support for indices and basic cursors over them but nothing like the power of SQL. My suggestion if you need a light-weight SQL is definitely SQLite.
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
http://www.sqlite.org
SQLite will work without requiring your App User to install SQLExpress or any other database engine, making it a good option for desktop applications.
Use SQLite as standalone database and integrated part of your applications.
Main benefits:
data is stored inside a single file, easy to pull/edit
ships as part of your application as dll, no separate
installation/configuration needed
i found some info about the database on the Microsoft website database info
there is a embedded database engine. Esent
If it is small set of user specific data, storing at windows registry is a good option.
No, there is no inbuilt database available.
But there are good alternatives, like the mqsql express server or a SQLITE database, which is basically a single database file which is accessed through a library in your project. So if you use SQLITE, you do not need to instal anything.

Storage for large volume of objects

I'm building a C# application where the end users won't have any sql database manager. I need a way of storing around 3 million objects (with roughly 10-20 string fields) so that the program can import the info. I've tried binary formatting but im getting out of memory exceptions due to the large amount of data. Is there any other way to store the objects in a speedy and size efficient way?
Thank You
This is what databases are made for. It doesn't matter that the end user won't have a database system already. There are a number of light-weight options available that you can deploy with your app. Here are three:
If you are Windows-only, then the Access database engine is built into the operating system. Just build a database with only table definitions (no records), and your app will be able to use it.
There is an implementation of sqlite completely in managed code, allowing you to compile it directly into your app.
Sql Server Compact Edition is just two *.dll files that are easy to deploy with the app.
None of these options require you to have anything running in the background on the target system.
You could also consider HDF5. This is designed for large-volume, high IO, distributed and high-performance computations. It is very flexible and imposes no install restriction on your application (can be completely self contained).
Hope this helps!

Database on a server without installation?

Right now I am having a customer who is working with several businesses. He is working with their data but is not allowed to directly access their databases. We thought of using SQLite or SQL CE and storing a copy/part of the original database as a file on a network share. Now the problem is that SQL CE is not supporting it and SQLite highly recommends not to do so.
First of all the performance is a huge problem, since our customer is working with a lot of data (up to several gb). The second problem is that SQLite has problems (actually the underlying os functionality for file locking is the problem) with concurrent usage of the database, when it is stored on a network share. I did a lot of research on that topic and many people say that it is just a matter of time that the database gets currupt.
Does anyone know a better solution to that problem or a workaroung which lets me use SQLite? It does not need to be a file based database, as long as nothing needs to be installed or run on the server.
Thanks, David.
If you are going to store data on a network share and have concurrent users accessing it you are going to need a db that can handle concurrent access. MS Access will quickly die if under concurrent access as will SQL Lite.
SQL Server Express is free and works very well. PostgreSQL as suggested by Maxim is an open source full featured db that will do the job very well but may be overkill.
You could also look at Redis ... fast lightweight in memory no sql db that also has capability to persist to file.
You can try PostgreSQL. It is very easy to configure, and is rather reliable. It also support server export/import options.
And any of this makes sense, if you client is able to get his hands on an exported database somehow.

C# - XML vs MySQL

In this program I'm writing, it would need frequent database communication, and at the moment I'm using just XML files. Is there really a benefit from using MySQL or SQL in general over XML. Just note that I'm using C# so MySQL is not very fun to deal with in it (from what little experience I have).
In terms of maintaining data stored in XML files vs. a relational database (Mysql, in your case), the database is far more robust than simple XML files. But this is simply an exercise in determining the needs of your application.
MySql, like many other RDBMSs, will provide much more than just a place to park your data. The biggest advantage to using a modern db such as MySql is ACID support. This means you get all-or-nothing transactions, ensuring consistency through your data.
You also get referential integrity to ensure that related records stay intact and don't leave you with abandoned references to other data records. We could go on and on to discuss the value of locking or the power of stored procedures.
But really, you should consider the needs of your application. If you do significant gymnastics to keep your data in order or you care about shared access and file locks while trying to read and write data, you need to punt on your XML file basis. No need trying to find ways around these issues when a basic mysql database will solve those issues.
If there's truly relational data...you'll almost always benefit from using a RDBMS. Retrieving data will be faster with the backing of a query engine rather than tying together XML nodes. You'll also get referential integrity when inserting data into the structure.
There is an ADO.NET provider for MySQL, so you shouldn't have any more difficulty dealing with a MySQL database than MS SQL Server.
You could even download DbLinq and give their LINQ to MySQL functionality a shot. Could make things even easier (or you could use Entity Framework with the MySQL ADO.NET provider).
The size of XML documents can be a large factor. In XML you either produce large and complicated text files with a huge amount of additional data or your data is split up accross several files. Managing these files can be a headache. Using a SQL database will allow you waste less disk space.
SQL is faster than using XML.
Any SQL database will give you access to a whole set of permissions and role capabilities that may be difficult to enforce using XML.
If you have relational data, a database would work. As an alternative to MySQL, if you aren't looking for a centralized solution, you can use SQLite. SQLite runs in-process (meaning the program running it is it's own "database server") and requires no installation other than distributing the DLL file containing it.
Robert Simpson has written System.Data.SQLite, a SQLite Data Provider for the .Net framework. It's free and open source (like SQLite) and works and feels as native as System.Data.SqlClient does. It supports standard ADO.Net conventions, Linq, and the Entity Framework.
I've used System.Data.SQLite for projects at work for applications that need to run fast and cache data locally for comparison between multiple runs (data processing and job scheduling). Firefox is a good example of an application using SQLite, Firefox 3 uses SQLite for it's Cookies, the Downloads history, Form autocomplete, and most importantly your web browsing history.
Again SQLite is meant for direct application use and lacks features like user authentication and schema permissions. It has issues if multiple programs try to write to the same database (those can be worked around but nothing like what a real RDBMS can do). It's biggest advantage is it doesn't need to be installed and set up to work like MySQL does. In the C# case all you have to do is reference System.Data.SQLite and copy the .dll file along with your program and it'll work.

Any ORMs that work with MS-Access (for prototyping)?

I'm in the early stages of a project, and it's not clear yet whether we'll need a "real" database (i.e. SQL Server et al). So I've been doing some prototyping using MS-Access, which is working fine so far. (developing in C#/VS2008/.Net 3.5/MS-Access 2000).
However, the object-relational impedance mismatch is already becoming annoying, and will only get worse as the project evolves.
I have not been able to find an ORM that will work with MS-Access. Any suggestions?
Edit - Follow Up
We ended up using Fluent NHibernate, mainly because it Automaps our object model to a relational database, which has been a huge win for us. Most of the FNH code samples we found used SQLite, and this worked so well that we intend to use it for our production database. (The app is a desktop scientific data collection and analysis package).
MSAccess files can be set up as an ODBC source on Windows machines. Almost any ORM will allow you to use ODBC. Here is a quick tutorial on how to set that up, it's outlined for Win2k but the process is the same for XP+. You also need to have MDAC installed on your box.
NHibernate seems to have native support of MSAccess as well, see here. I've never used it though. It also has an ODBC driver.. Many others support ODBC as well.
And again, as others are saying.. MSAccess does not scale... period. Installing a real database server is fairly easy, so I'd recommend SQL Server Express as others have, or even MySQL or Postgre, whatever is easier to set up.
If this is an application that you intend to deploy to clients, with each client having their own unique database, I would recommend another solution entirely, SQLite. SQLite gives you database power on an app by app basis. If you have a central database server, one of the previously mentioned solutions would be best.
There's only one scenario when choosing the Access Database Engine is a good choice: when building a self-contained Access application using Access Forms (though choosing to use Access in the first place is a questionable choice ;)
The database engine that VS2008 plays nicest with is SQL Server and you will have no problem finding an ORM that plays nice with SQL Server.
Can't give you an answer to your question, but instead of Access you might want to consider one of the following options:
SQL Server Express: is free and compatible with the full SQL Server
SQL Server Compact: also free, does not require any deployment/installation, does not support all features (e.g. no stored procedures).
At this stage, if you are unsure whether you need a "real" database or not, I'd skip MS Access and go straight to sql server express. It's free and still allows you to do everything you need to.
Plus, if you later decide you need to scale up, then you can without any pain.
I recommend you to use something like Microsoft SQL Server or PostgreSQL for prototyping. If you don't want to learn specific SQL syntax and install special tools for designing database schema, you can use ORM that automatically generates database schema from your persistent classes declaration. Anyway this approach is very effective for prototyping.
LLBLGen works with Access
Access is just a bad, bad idea. I believe MS only includes Access in Office to keep legacy users happy.
Even if you find an ORM that will work with an Access database, with few exceptions you're locking yourself into a niche tool that likely will not work out-of-the box with a real database engine. If you decide to switch to a real database engine later on, you'll not only have to deal with migrating the database, but switching to a different ORM.
See this comparison between SQL Server Express and SQL Server Compact. The comparison document also mentions some problems with other data stores, including Access.
If you are REALLY concerned about being able to install SQL Server Express, consider SQL Server Compact:
it can be linked into your redistributable app. No need to install a service (which may require admin rights during install of your application); everything is taken care of when you install your app. This makes the most sense if you need the data to reside on the user's machine instead of a server, and is most analogous to using Access.
It's less powerful than Express (doesn't support views, triggers, stored procedures, which I consider a requirement)
Can be scaled up to Express or other SQL Server versions very easily
Suitable for small-footprint installs like tablets, mobile devices, etc.
Always keep scalability in mind when designing any application. You don't want to wind up having to write a PHP->C++ compiler if/when your app becomes successful just because you picked the wrong tool up front.
While we're at it:
The big issue with Access (or, in this case, the Jet engine, which is the part you'd really be using when integrating an Access database with a .NET app) is that there is no "server" that handles datase requests. The engine, hosted in your app, must read and write directly to a file on disk that contains the database. Whenever this happens, the file must be locked to prevent concurrent writes. Dirty reads become more common as the number of users grows, as does the potential for database corruption.
Imagine having every customer at a large restaurant trying to simultaneously enter the kitchen to write down their orders or retrieve their food. Chaos would result. There'd be a lot of broken dishes, the kitchen would be a mess, you'd be lucky to get what you ordered in any sort of edible condition. With one customer, this probably works fine. With 5, eh, maybe. With 20,50,1000? Not so much.
So, the restaurant industry introduced waiters and managers that buffer IO to the kitchen. The database server application does something roughly analogous to this by restricting access to the files on disk. Everyone gets what they want, faster and in a much more reliable way, and the data store is protected.

Categories