简体   繁体   English

使用本地数据库的WPF C#应用程序

[英]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. 我的任务(和目标)是使用C#在WPF中创建一个应用程序,它可以连接到/使用存储在用户计算机上的本地数据库。 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. 数据库“文件”应该易于加载并在机器之间移动,并且如果可能的话,在应用程序安装期间在用户的PC上创建。 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管理工具中修改选项,以更新其大部分内容。 DB's file security is not an issue in the case of this project. 对于此项目,DB的文件安全性不是问题。 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). 到目前为止,我已经在Microsoft SQL Server 2014 Express中创建了一个数据库,但说实话我不知道是否可以按照我所描述的方式将此数据库移动到另一台PC(至少在没有安装新的SQL Server实例的情况下)这台机器)。

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#. 在这种情况下,有多种已建立的解决方案可用于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.) MySql (您可能首先要检查使用它的许可限制。)

My recommendation would be SQLite because it is very easy to get running with it. 我的建议是SQLite,因为它很容易运行它。 Additionally, there are many, many DB admin tools out there that are freely available. 此外,还有许多免费提供的数据库管理工具。 My personal favorite, however, is a paid product, Firebird Maestro . 然而,我个人最喜欢的是付费产品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 这是一个获得启动的教程: 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. 您可以使用SQLite,MS SQL CE或许多其他选择。

Depending on your scenario you can also use XML or Json files as well. 根据您的方案,您也可以使用XML或Json文件。

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. 我建议您选择SQL Server Compact(CE)而非SQLite,原因如下:如果您使用的是Visual Studio Express版,则可以使用Entity Framework到SQL Server CE开箱即用。 SQLite will require you to have paid version of VS in such case. 在这种情况下,SQLite将要求您拥有VS的付费版本。

The lack of stored procedure support in SQL Server CE may be compensated by the power of L2E queries. SQL Server CE中缺少存储过程支持可以通过L2E查询的强大功能得到补偿。 The only considerable limit is database file size (4 Gb only). 唯一可观的限制是数据库文件大小(仅限4 Gb)。 Plus, you can silently deploy SQL Server CE runtime with your application (called "private deployment"). 此外,您可以使用您的应用程序静默部署SQL Server CE运行时(称为“私有部署”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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