2

I'm quite new to databases, although I've been doing tutorials and such to come up to speed, and I got to wondering: If I have a database that was created in MySQL or MSSQL, can I access it using C# without having a database server installed on the machine? And if I write a program that uses a small database, say 4 tables with less than 100 elements each, how would I go about deploying that in my released C# program? Please bare in mind that this question isn't about the merits of using a database in a program, it's about the mechanics of accessing a database file (.mdf), from a released C# program, without having a database server installed on the target machine. I've seen various articles on the MSDN dealing with this, but I haven't found one that answers this question.

Thanks

Cynon
  • 117
  • 1
  • 10
  • It is actually pretty *uncommon* to have a database program installed on the client... – Marc Gravell Dec 09 '13 at 12:35
  • well, you must have drivers to access the database.. And it would be usefull for testing to access the dabase on the "test"server – lordkain Dec 09 '13 at 12:36
  • If I understand what Marc said, I can embed the database in the application, and use the C# libraries to access the mdf file. I'm not sure if that means embedding a database server or just using the C# libraries to access the mdf file. – Cynon Dec 09 '13 at 13:18

3 Answers3

2

There are essentially 3 types of database implementations:

  • server install - think "SQL Server", "Oracle" - here, the database is purely on the server; the caller requires the client library (i.e. something that understands the database protocol), but that can usually be deployed as part of the application, or is part of a standard framework that is already on the machine; here the central server would typically service multiple clients concurrently
  • client install - think "SQL Server Express" etc - here there is a dedicated database utility installed on the client machine; again, the application needs the client library, but the database engine is typically a separate product / install that needs to happen for each client
  • embedded databases - this is probably what you are aiming for; in this scenario, the "client library" actually includes the entire database engine, allowing the application to be entirely self-contained; this tends to offer the least features of the three, but usually enough for most common scenarios

So: as long as you limit yourself to the third category, you should be fine.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • In case number 3, how does one embed the database engine into the application? Would I use something like SQLite, or do the C# libraries include classes that act like a database server? – Cynon Dec 09 '13 at 13:21
  • SQLite does the trick. EDIT: There are nuget packages that let you use Entity Framework with SQLite which makes the C# code used to interact with the DB much easier. – ledgeJumper Dec 09 '13 at 13:22
2

I'd recommend you to use SQLite, you don't need the client to have any DBMS installed. It's performance is really good, and you just need to get the nuget package to get started.

Community
  • 1
  • 1
D.Rosado
  • 5,634
  • 3
  • 36
  • 56
1

Sounds like you are looking for an embedded database. Have a look at this question. SQL Server Compact from that list might be just what you are looking for.

Community
  • 1
  • 1
Konstantin Spirin
  • 20,609
  • 15
  • 72
  • 90