gpt4 book ai didi

sql-server - dotnet ef 数据库更新中与网络相关或特定于实例的错误

转载 作者:行者123 更新时间:2023-12-02 08:19:28 24 4
gpt4 key购买 nike

我正在学习使用 Visual Studio 构建 ASP.NET Core MVC 应用程序 this教程。在“Adding a model ”步骤中,我创建了一个新的单独项目(如说明中所述),但是当我运行 dotnet ef database update 时,出现以下错误:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)



但是我已经安装了 SQL Server 并且 SQLEXPRESS 服务正在运行。我也尝试打开端口,但没有帮助。

最佳答案

设置本地数据库

模板的连接字符串用于 localdb专门针对 mssqllocaldb实例。确保您拥有两者。

appsettings.json

{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-MvcMovie-87ad796f-548e-4862-9713-d2976453319e;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}

确保您已安装 LocalDB。 要检查,请打开命令提示符并运行 sqllocaldb .这将打印 LocalDB 命令行帮助信息。如果您没有 LocalDB, then install it.

确保您有一个名为 MSSQLLocalDB 的实例. 要检查,请运行 sqllocaldb info .如果您没有该实例,则需要创建它 ( sqllocaldb create mssqllocaldb ) 或更改连接字符串以指向您拥有的实例。

我的机器上的工作示例
dotnet ef database update命令在我的机器上运行。这是在我的提示下各种命令的输出。
> sqllocaldb info
MSSQLLocalDB

> dotnet ef migrations add Initial
Project MvcMovie (.NETCoreApp,Version=v1.0) will be compiled...
Compiling MvcMovie for .NETCoreApp,Version=v1.0
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:01.7783361

Done. To undo this action, use 'dotnet ef migrations remove'

> dotnet ef database update
Project MvcMovie (.NETCoreApp,Version=v1.0) was previously...
Done.

关于sql-server - dotnet ef 数据库更新中与网络相关或特定于实例的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38638757/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com