【问题标题】:ASP.Net Core 3.1 Web API (ApiController), EF Core 3.1 {The system cannot find the file specified.}ASP.Net Core 3.1 Web API (ApiController), EF Core 3.1 {系统找不到指定的文件。}
【发布时间】:2021-08-14 16:39:43
【问题描述】:

我之前做过几个 .net core api 的 EF Core。事实上,我在这里 https://github.com/xmione/.Net-Core-2.2 创建了一个工作的 .Net Core 2.2 版本。

现在我尝试为 core api 和 ef core 做 core 3.1。每个,当然有它的独立项目。 我可以很好地执行 Add-Migrations 和 Update-Database。数据库和表将自动创建。我还可以访问 weatherforcast api 方法,它完美地显示了数据。 UseInMemoryDatabase 也很棒。但是当我开始做 UseSqlServer() 时。那是我遇到错误的时候:

Win32Exception: The system cannot find the file specified.
Unknown location

SqlException: 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: SNI_PN11, 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.)
Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, bool breakConnection, Action<Action> wrapCloseInAction)

我可以在 Visual Studio 和 SQL Server Management Studio 中看到创建的数据库和表,我可以使用它来添加、编辑和删除记录。但是当我运行 API 并对其进行测试时。它失败并显示上面的错误。 有人能指点我这里最快的方向吗?谢谢。我的代码位于以下链接:

https://github.com/xmione/ReactJS/tree/master/ReactJS.Redux.Web.API/API

非常感谢!

【问题讨论】:

    标签: asp.net-core entity-framework-core


    【解决方案1】:

    我刚刚想出了如何解决这个问题。我刚刚在https://code-maze.com/net-core-web-api-ef-core-code-first/ 关注了这篇文章。 实际上在 Github.com 上有一个源代码:https://github.com/CodeMazeBlog/ef-code-first

    我只是按照文章,下载源代码并将其与我的代码进行比较。我发现我缺少一些重要的存储库类。

    感谢那篇文章,我在 Github.com 中的代码已经修复。 我的 Web API 源代码位于: https://github.com/xmione/ReactJS/tree/master/ReactJS.Redux.Web.API 我希望这对需要它的人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      • 2021-04-22
      • 1970-01-01
      • 2020-07-13
      • 1970-01-01
      • 2022-11-11
      • 1970-01-01
      相关资源
      最近更新 更多