[C#] How to create a local database file with no connection to a server

Started by
14 comments, last by Kylotan 16 years, 6 months ago
I was wondering if anyone had any information on using C# to create a database that is stored on the users PC that would be accessed without any sort of connection to a server. I've been looking for tutorials online, but all the tutorials I find are for connecting to another computer running SQL Server. That is not what I want. I just wanted to use a database to store game data. Anyone got any links?
Advertisement
XML would most likely be the way to go. Lot of stuff out there on how to do it.

theTroll
You can use a C# wrapper for sqlite:

click.
There's also the free SQL Server 2005 Compact Edition.

MySQL servers can be embedded in an app. Im actually knee deep in researching this myself at the moment.
From the MySQL 5.0 Reference Manual :

"We also provide MySQL Server as an embedded multi-threaded library that you can link into your application to get a smaller, faster, easier-to-manage standalone product. "

I know for C#, there is a plugin (for visual studio) called connector.net. Im just learning this stuff, but with connector, connecting/editing/etc.. a database is as easy as :

1) Add reference MySQL.Data

2) using MySql.Data.MySqlClient;

3) Create connection object :
MySql.Data.MySqlClient.MySqlConnection conn = new MySqlConnection();

4)Create connection string
conn.ConnectionString = "server=127.0.0.1;Uid=root;Pwd=jason;Database=test;";

5) call conn.Open()

And theres handy GUIs too.
Crap.

Only in C++ at the moment.

The ability to embedded SQL server using C# is planned for 5.2.

But tons of other people want to do it too.
http://forums.mysql.com/read.php?58,5043,159981#msg-159981


Embedding the MySQL engine will likely require you to licence your code under the GPL, FWIW. If that's not your intention, read the licence.

Also, I don't see how XML is the way to go: XML isn't a storage solution, it's only a markup language. It's perfectly possible to have a SQL DB that stores its data in a bunch of XML flat files (although that would be moronic in 99% of the cases), but the interface would still be SQL. XML won't allow you to run queries, to update, select, delete, ... your data, to alter, create, delete tables, to have checks, triggers, stored procedures, etc. All of that you'll have to code by yourself.

I'd suggest looking at SQLite or, if you need something heavier and don't need portability to non-Windows systems(*), Firebird, which has an embedded server. This article apparently explains how to get it to work with .NET.


(*) The standalone server apparently is a Windows-only feature, but the fullblown server is available for non-Windows systems as well.
let_bound

Firebird sounds like exactly what the OP (and myslef) have been looking for.

How ironic. OP username is BrknPhoenix, and the solution to his problem was a thing called 'firebird'. Lol, nerd humor I guess.

Quote:Original post by let_bound
Embedding the MySQL engine will likely require you to licence your code under the GPL, FWIW. If that's not your intention, read the licence.


MySQL has multiple licences, you can either use the GPL licence or pay for a custom proprietary licence.

http://www.mysql.com/oem/licensing.html
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

This topic is closed to new replies.

Advertisement