0

使用 Visual Studio 2017,对于 C# 项目,如何在一个单独的可移植文件中创建我的 SQL 数据库?

4

2 回答 2

1

Visual Studio“本机”数据库是 LocalDB。此信息很快就会过时,但这是当前情况,从下面的链接中总结

https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-ver15

  • LocalDB 可以通过 Visual Studio 安装程序安装
  • SqlLocalDB.exe实用程序可让您管理 LocalDB(即启动/停止/创建/删除)
  • LocalDB 无法通过 SQL Management Studio 远程管理。
  • 对于安装在用户计算机上的每个版本的 LocalDB,都存在一个 LocalDB 的“自动”实例。这是公开的,为用户自动创建和管理
  • 使用 LocalDB 最简单的方法是使用连接字符串连接到当前用户拥有的自动实例Server=(localdb)\MSSQLLocalDB;Integrated Security=true。要使用文件名连接到特定数据库,请使用类似于以下内容的连接字符串进行连接Server=(LocalDB)\MSSQLLocalDB;Integrated Security=true;AttachDbFileName=D:\Data\MyDB1.mdf

I've never managed to find clear instructions on how this should be deployed. Suffice to say you should be able to easily install LocalDB on the target machine and deploy your MDF file for it to use.

If you would care to expand on your use case, there might be other options.

I have a software that I will run to gather data. This software will, hopefully in a near future, allow to consult the data. But if I am the "gatherer" the "reader" will be someone else. I need to send the data there.

For example you could use a cloud database (Azure SQL would be the visual studio native platform). You don't need to install anything, it's automatically backed up. It's publicly accessible to anyone (and can be locked down). Downside is it's about $8.00 USD a month for 250Gb

于 2021-09-23T23:48:07.050 回答
0

SQLite

SQLite 数据库是单个文件。表和数据、触发器、外键和约束都存储在此文件中。您的应用程序通过调用 SQLite 读取和写入数据库。当您执行 SELECT 或 UPDATE 时,SQLite 读取和写入文件......

从这里复制了这段文字:https ://www.c-sharpcorner.com/UploadFile/afenster/using-sqlite-with-net/

您还可以在该页面上查看如何使用数据库的示例。网上还有很多其他教程。

于 2021-09-22T13:21:19.740 回答