简体   繁体   中英

WPF C# application using local database

I am a novice when it comes to using a database in an application. My task (and sort of a goal) is to create an application in WPF using C# that can connect to/use local database stored on user's computer. The database 'file' should be easy to load and move between machines and, if possible, created on user's PC during the application's installation. The database needs to have an option to be modified from within the application as well as from a respective DB's management tool for updating a large portion of it's content. DB's file security is not an issue in the case of this project. I know that what I've described may have no sense at all and I could simply export applications settings to a file but it's not what I am looking for in this case. So far I have created a DB in Microsoft SQL Server 2014 Express but to be honest I don't know if it's possible to move this DB to another PC in the way I have described (at least without installing a new instance of SQL Server on this machine).

As I have mentioned in the beginning I am a novice regarding database's so any advice is appreciated.

If I understood you correctly you are looking for some kind of portable database, right? In this case there are multiple established solutions available that work well with C#.

These are a few that might be worth a look for you:

Full grown databases that can be used as embedded version without a server running in the background.

  • Firebird
  • MySql (You might first want to check the license restrictions for using this.)

My recommendation would be SQLite because it is very easy to get running with it. Additionally, there are many, many DB admin tools out there that are freely available. My personal favorite, however, is a paid product, Firebird Maestro . I found working with it quite intuitive and although it is a paid-for product, it is still quite affordable (they also have multiple promotions per year).

But still, there are plenty of other free tools to choose from. Your favorite internet search engine will be your friend. :-)

I suggest you take a look at how to setup a code first database. It might need some research but its well worth it. Especially if you are comfortable with code and dont got a database setup yet. Here is a tutorial to get starterd: http://msdn.microsoft.com/en-us/data/jj193542.aspx

There are a great many number of embeddable databases that you can use, each with its own benefits and drawbacks. You can use SQLite, MS SQL CE or any other of many choices.

Depending on your scenario you can also use XML or Json files as well.

I would recommend you to choose SQL Server Compact (CE) over SQLite for the following reason: if you are using Visual Studio Express edition, you will be able to use Entity Framework to SQL Server CE out of the box. SQLite will require you to have paid version of VS in such case.

The lack of stored procedure support in SQL Server CE may be compensated by the power of L2E queries. The only considerable limit is database file size (4 Gb only). Plus, you can silently deploy SQL Server CE runtime with your application (called "private deployment").

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