Sign in to follow this  

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

This topic is 3724 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Quote:
Original post by SimonForsman
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


Sorry, I should have added "if you don't want to pay for a proprietary licence".

Share this post


Link to post
Share on other sites
[opinion]
I think a full DB option is major over kill in this case. An XML file can do everything the OP wants with less overhead and be human readable. Just because you think you need something doesn't mean you do.
[/opinion]

theTroll

Share this post


Link to post
Share on other sites
My company recently deployed an application which uses SQL Server Express for local storage. It has worked very smoothly, and if the clients want to later scale to heavier versions (MSSQL Standard, Enterprise), we only need to modify a single connection string in the application configuration.

SQL Server Express is extremely cost-effective because it can be distributed royalty-free (you do need to accept a distribution agreement). The only downside is that the database engine can only be installed in Windows environments.

As Mutex said, there is even a lighter version available, called SQL Server Compact edition. This engine is robust enough to easily embed a database in your application, but it does sacrifice some scalability features as compared to Express and up.

Share this post


Link to post
Share on other sites

This topic is 3724 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this