[英]How can I connect to ASP.NET Core's WebApplication.db database?
I'm experimenting with ASP.NET Core and have created a new Web Application (MVC) site with it: 我正在试验ASP.NET Core,并用它创建了一个新的Web应用程序(MVC)网站:
git init CoreWebApp
cd CoreWebApp
dotnet new -t web
dotnet restore
After the code is bootstrapped I ran the initial EF migration 自举代码后,我进行了初始EF迁移
dotnet ef database update
At this point a database is generated at ./bin/Debug/netcoreapp1.0/WebApplication.db
and the site runs and allows users to be registered and login successfully. 此时,将在
./bin/Debug/netcoreapp1.0/WebApplication.db
生成一个数据库,该站点将运行,并允许用户注册和成功登录。 I'd like to connect to that database via SSMS, LINQPad, or another standard SQL Client, but am having troubles. 我想通过SSMS,LINQPad或其他标准SQL Client连接到该数据库,但是遇到了麻烦。 The "open file" prompts typically look for a
.mdf
extension and complain about the .db
file. “打开文件”提示通常会查找
.mdf
扩展名,并抱怨.db
文件。
How do I connect to an ASP.NET Core, EF Generated WebApplication.db file from a SQL Client? 如何从SQL客户端连接到ASP.NET Core EF生成的WebApplication.db文件?
The dotnet new
command is created with portability in mind so it can also run on non-Windows systems. 创建
dotnet new
命令时要考虑到可移植性,因此它也可以在非Windows系统上运行。 Since there is no SQLExpress for Linux and Mac, the template is created with SQLite as database. 由于没有适用于Linux和Mac的SQLExpress,因此使用SQLite作为数据库创建模板。
So you need an SQLite client to open it. 因此,您需要一个SQLite客户端来打开它。
Of course you're free to replace with any provider which supports EntityFramework Core, like SQLServer. 当然,您可以随意替换为任何支持EntityFramework Core的提供程序,例如SQLServer。
Just replace 只需更换
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.1",
in your project.json with 在你的project.json中
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
and 和
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
with 与
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
in Startup.cs and finally the connection string in appsettings.json 在Startup.cs中,最后在appsettings.json中连接字符串
"ConnectionStrings": {
"DefaultConnection": "Data Source=WebApplication.db"
},
with the 与
"ConnectionStrings": {
"DefaultConnection": "Server=.\SQLExpress;AttachDbFilename=C:\MyFolder\MyDataFile.mdf;Database=dbname;Trusted_Connection=Yes;"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.