无法使用.NET 7.0中的包管理器控制台创建数据库。

huangapple go评论73阅读模式
英文:

Could not create database using package manager console in .NET 7.0

问题

我现在正在学习 .NET 并跟着课程学习,我的目标是创建 CRUD 应用程序,所以我需要一个数据库来配合。我成功创建了初始迁移,但数据库更新无法工作。

如果连接字符串看起来像这样,我会收到以下错误:
"ConnectionStrings": {
"QuotesAppContext": "Server=(localdb)\\mssqllocaldb;Database=QuotesAppContext-811c920d-aeb7-4d04-8ba6-5c9a48d8b492;Trusted_Connection=True;MultipleActiveResultSets=true"
}
> (provider: SNI_PN11, error: 50 - 本地数据库运行时出错。无法创建自动实例。请查看 Windows 应用程序事件日志以获取错误详情。

我已经在 Windows 11 上安装了 SQL Server 和 SQL 管理器,没有问题。如果我将连接字符串更改为这样:

"ConnectionStrings": {
"QuotesAppContext": "Server=(localdb)\mssqllocaldb;Database=QuotesAppContext-811c920d-aeb7-4d04-8ba6-5c9a48d8b492;Trusted_Connection=True;MultipleActiveResultSets=true"
}
删除了反斜杠之后,现在出现问题:

> 无法创建类型为 'QuotesAppContext' 的对象。

对我来说,这似乎是一个无休止的循环,感谢您的帮助。请指导如何执行 database-update 并使数据库实例正常工作。
英文:

Im learning .net now and following along the course,my goal is to create CRUD app so i need a database to work with it, i have succesfuly created initial migration but database-update doesnot work

> (provider: SNI_PN11, error: 50 - Local Database Runtime error
> occurred. Cannot create an automatic instance. See the Windows
> Application event log for error details.

im getting this error if connection strings look like this

"ConnectionStrings": {
    "QuotesAppContext": "Server=(localdb)\\mssqllocaldb;Database=QuotesAppContext-811c920d-aeb7-4d04-8ba6-5c9a48d8b492;Trusted_Connection=True;MultipleActiveResultSets=true"
  }

i have installed both sql server and sql management on windows 11 without problem
and if i change connection string to this

"ConnectionStrings": {
    "QuotesAppContext": "Server=(localdb)\mssqllocaldb;Database=QuotesAppContext-811c920d-aeb7-4d04-8ba6-5c9a48d8b492;Trusted_Connection=True;MultipleActiveResultSets=true"
  }

deleting \ problem now is

> Unable to create an object of type 'QuotesAppContext'.

so it seems like an endless circle to me, thanks you for your help

write database-update and get database instance working

答案1

得分: 0

我找到了对我有用的答案,在regedit中找到此文件夹

"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SQL Server\UserInstances"

然后删除其中的所有内容,之后再次运行Update-Database命令,一切都应该正常工作。

附言
我尝试重新安装SQL Server,添加端口,但这个解决方案对我有用。

英文:

I find the answer which have worked for me,find this folder in regedit

"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SQL Server\UserInstances"

and delete everything inside of it,and after that run Update-Database command again everything should work fine
P.S
i have tried reinstalling sql server,adding ports, but this solution worked for me

huangapple
  • 本文由 发表于 2023年2月19日 04:32:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75496217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定