文件中的 C# 数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/623107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# database in a file
提问by
How do i create a db file in C#? a friend told me it was in the toolbox and not to use sqlite. I dont see anything that could be it, nor what it is called. google didnt help:(
我如何在 C# 中创建一个 db 文件?一个朋友告诉我它在工具箱中而不是使用sqlite。我没有看到任何可能是它的东西,也没有看到它叫什么。谷歌没有帮助:(
采纳答案by Rex M
There is no file-based database provider built in to c# or the .NET Framework. There are of course pre-existing connectors for using SQL Server (which includes SQL Express), but if you need a fully functional RDBMS that is file-based, you need to use something like SQLiteor Firebird(also a fan of VistaDB, not free or open source but VERY solid and pretty affordable).
c# 或 .NET Framework 中没有内置的基于文件的数据库提供程序。当然有使用 SQL Server(包括SQL Express)的预先存在的连接器,但是如果您需要一个功能齐全的基于文件的 RDBMS,您需要使用类似SQLite或Firebird(也是VistaDB的粉丝,而不是免费或开源,但非常可靠且非常实惠)。
回答by TheTXI
You are mistaken. Databases are not developed in C#. Databases are built using a database system such as Oracle, MS SQL Server, MySQL, and numerous others.
你误会了。数据库不是用 C# 开发的。数据库是使用 Oracle、MS SQL Server、MySQL 等数据库系统构建的。
Once you build a database using one of the above providers, you can then perform actions on the database using your programming language of choice (in your case C#) to get data out of and put data into it.
使用上述提供程序之一构建数据库后,您就可以使用您选择的编程语言(在您的情况下为 C#)对数据库执行操作,以从中获取数据并将数据放入其中。
回答by Dustman
If you are using Visual Studio or Web Developer Express, there are indeed ways to easily create a MS SQLExpress database. Just go to Add New Item... and it should be one of the available file types.
如果您使用的是 Visual Studio 或 Web Developer Express,确实有一些方法可以轻松创建 MS SQLExpress 数据库。只需转到添加新项目...它应该是可用的文件类型之一。
Keep in mind you have to have installed either Microsoft SQL Express Edition (free, as in beer!) or Microsoft SQL (very un-free!, in all senses). If you haven't done this, you don't get the option of creating a database file so easily. If you have got it yet, you can get it here.
请记住,您必须安装 Microsoft SQL Express Edition(免费,就像在啤酒中一样!)或 Microsoft SQL(非常不免费!,在所有意义上)。如果您还没有这样做,您将无法如此轻松地创建数据库文件。如果你已经得到它,你可以在这里得到它。
As other answerers have mentioned, strictly speaking this is NOT a C# feature. MS SQL and it's derivatives, are database applications, much like Oracle, MySQL, or PostgreSQL. It's just that Microsoft Visual Studio makes using the Microsoft database product very easy by default. Differentiating between C#, Visual Studio, and any database programs will probably get you better answers, faster, no matter where you ask. :)
正如其他回答者所提到的,严格来说这不是 C# 功能。MS SQL 及其衍生产品是数据库应用程序,很像 Oracle、MySQL 或 PostgreSQL。只是 Microsoft Visual Studio 在默认情况下使使用 Microsoft 数据库产品变得非常容易。区分 C#、Visual Studio 和任何数据库程序可能会为您提供更好、更快的答案,无论您在哪里提问。:)
回答by spender
Could it be...
会不会是...
SQL Server Compact Edition– A lightweight, in-process database engine designed to run on devices and desktops and is geared toward local data storage. Compact Edition includes a subset of SQL Server 2005 data types and shares common elements of the Transact-SQL (T-SQL) language with the data service engines.
SQL Server Compact Edition– 一个轻量级的进程内数据库引擎,设计用于在设备和桌面上运行,并面向本地数据存储。Compact Edition 包括 SQL Server 2005 数据类型的子集,并与数据服务引擎共享 Transact-SQL (T-SQL) 语言的公共元素。
回答by eglasius
On the Add New Item menu: "Service-based Database" or "Sql Server Database" if it is an asp.net application. I am sure your friend meant it as "create a sql express db file in Visual Studio".
在“添加新项目”菜单上:“基于服务的数据库”或“Sql Server 数据库”(如果它是一个 asp.net 应用程序)。我相信你的朋友的意思是“在 Visual Studio 中创建一个 sql express db 文件”。
That said, if you wanted to fill an empty database, with tables that correspond to a c# model, you could create a linq2sql model, and use its CreateDatabase to do that for you :)
也就是说,如果你想用与 ac# 模型对应的表填充一个空数据库,你可以创建一个 linq2sql 模型,并使用它的 CreateDatabase 来为你做这件事:)
You might want to check this http://quickstarts.asp.net/QuickStartv20/aspnet/doc/data/vwd.aspx(visual web developer link, but it applies).
您可能需要查看此http://quickstarts.asp.net/QuickStartv20/aspnet/doc/data/vwd.aspx(可视化 Web 开发人员链接,但适用)。
For a full/in-depth explanation of how SQL express can be used with a semi file based approach check and its limitations: http://www.databasejournal.com/features/mssql/article.php/3704171/SQL-Server-2005-Express-Edition---Part-8---XCopy-Deployment.htm
有关 SQL express 如何与基于半文件的方法检查及其局限性一起使用的完整/深入说明:http: //www.databasejournal.com/features/mssql/article.php/3704171/SQL-Server- 2005-Express-Edition---Part-8---XCopy-Deployment.htm
回答by Robert
Every database has a file system
in some binary format more than likely custom and uses a cache
to control the flow of the database(s) lifetime.
每个数据库都有file system
一些二进制格式,很可能是自定义的,并使用 acache
来控制数据库生命周期的流程。
If you create a database system
, you will need some type of cache because you only want to read from the file if the cache has already released it.
如果您创建一个database system
,您将需要某种类型的缓存,因为如果缓存已经释放它,您只想从文件中读取它。
If you have 1000 clients tapping into the same db, you certainly don't want to read/write
to the file for each client request, so you want to manage a queue of clients and run it against the cache so that the cache knows not to release the db after its time span for lifetime is reached put to rather update the time span, therefore, not having to reload the file, if disposed and queued again, until the queue referencing the db object is empty.
如果您有 1000 个客户端访问同一个数据库,您当然不想read/write
为每个客户端请求访问该文件,因此您希望管理一个客户端队列并针对缓存运行它,以便缓存知道不释放db 在其生命周期的时间跨度达到后 put 而不是更新时间跨度,因此,如果再次处理并排队,则不必重新加载文件,直到引用 db 对象的队列为空。
Creating a well designed cache it used by all rdbms's so that duplicate objects are not created and files are not reloaded if not need be.
创建一个设计良好的缓存,它被所有 rdbms 使用,这样就不会创建重复的对象,并且在不需要时不会重新加载文件。
回答by Kbdavis07
You can use
您可以使用
FileDB - A C# database to store files
FileDB - 用于存储文件的 AC# 数据库
There is a MVC Example in the source that allows you to upload files and also has drag and drop support.
源中有一个 MVC 示例,它允许您上传文件并支持拖放。
It then saves it into just one file in a location that you specified.
然后将其保存到您指定位置的一个文件中。
Like this:
像这样:
private string pathDB = @"C:\CMS-MVC\Parts\FileManager\filedb-19055\trunk\MvcTest\Data\MvcData.dat";
That one file will store all of your files in that one "container".
那个文件会将您的所有文件存储在那个“容器”中。