如何解决ASP.Net Core 3.1 Web APIApiController,EF Core 3.1 {系统找不到指定的文件}
我之前已经做过几个.net核心api的EF核心。实际上,我在https://github.com/xmione/.Net-Core-2.2处创建了一个有效的.Net Core 2.2版本。
现在,我尝试为核心api和ef核心同时执行核心3.1。每个当然都有单独的项目。 我可以做添加迁移和更新数据库。数据库和表将自动创建。我还可以访问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
非常感谢!
解决方法
我只是想出了解决方法。我只是关注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 我希望这会对需要它的人有所帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。