简体   繁体   中英

Serverless Database in C#

Complete newbie question here: I'm just playing with C# for the first time and want to make a Windows Forms application which stores some info in a database structure, but obviously don't want to require something like MySQL to be installed on each client's computer. How do I go about this?

You can use SQLite . It doesn't require any installation or server on the client's computers. Here is an blog describing how to use it with .NET. It is easy to use, just add a reference to the System.Data.SQLite.dll .

Here is an open source data provider for .NET: System.Data.SQLite

From homepage : "SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain. "

You use a database that doesn't require an install. There are a few out there - there's Microsoft SQL Server Compact , which frankly is badly named, as it won't support the more useful SQL functions like stored procedures, views and so on. There's also VistaDB which does support stored procs, but requires purchase if you want Visual Studio plugins.

The answer is Embedded Databases. You've got quite a large list of Embedded databases that you can use:

Commercial:

  1. VistaDB - This database is written completely in managed C#.

Open Source:

  1. Firebird - .NET Driver
  2. SQLite - .NET Driver

You could write your data to XML files, or you could take a look at the Sql Server Compact Edition .

You could also work with objects and serialize/deserialize these to disk as binaries.

Of course the type of storage you choose depends a lot on the kind of data you're storing (and the volume of it).

An easy way to do it from .NET 3.5 onwards is to store your data in XML files and use Linq to XML . This allows you to use SQL-like commands on your data which are actually compiled into your application, so you get full IDE IntelliSense support and error checking.

Perhaps you could serialise a dataset and save it as XML. I'm a little confused why if you're playing around you would need to install MySQL on all client's computers. You could look at using SQL Express which is free perhaps?

Serialise Dataset:

http://blogs.msdn.com/yosit/archive/2003/07/10/9921.aspx http://msdn.microsoft.com/en-us/magazine/cc163911.aspx

The Easiest way will be SQL Server Compact, Because it integrates directly into the Visual Studio IDE (I'm just hazarding the guess here that you use VS). Add the "Local Database", Create your tables and be sure to make your Table Adapter with Select, Update, Insert and Delete methods. If during Database Creation you called your Dataset "DS" you will be able to instantiate a Table Adapter Object from

DSTableAdapters 

Namespace, and Use GetData() or Fill() methods to retrieve your Data, and Insert(), Update() and Delete() to Manage it.

VelocityDB works in a server less mode but can also be combined with a server when there is a need for it. It outperforms all the other choices mentioned here by roughly a magnitude, see comparison here . It allows you to use almost any .NET data structures persistently. The entire database engine and the optional server is implemented using C# code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM