首页 > 解决方案 > .net core 3.1 with EF Core 错误使用 NetTopologySuite 连接数据库

问题描述

在 appSettings 我有这个:

"ConnectionStrings": {
    "GeoLocation": "Server=localhost;Database=GeoLocationDB;Trusted_Connection=True;MultipleActiveResultSets=true;"
  }

我在 ConfigureServices 的启动文件中有下一个代码:

services.AddDbContext<GeoLocationContext>(o => o.UseSqlServer(Configuration.GetConnectionString("GeoLocation"), s => s.UseNetTopologySuite()));

在启动的配置方法中添加执行此操作的上下文:

context.Database.Migrate();

得到这个:

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.

奇怪的是我创建了一个迁移并运行更新数据库,它运行没有问题我不知道为什么迁移我没有得到同样的错误。

对于数据库,我可以毫无问题地登录 localhost,并看到在包管理器控制台中执行的迁移生成的更改。

通过 api 控制器(是微服务)中的代码,我尝试进行插入,它给了我同样的错误,我有几天试图理解为什么会发生这种情况,但我找不到问题。

提前致谢

标签: c#sqlentity-framework.net-coreentity-framework-core

解决方案


推荐阅读