.net core 如何解决此连接字符串错误?

.net core 如何解决此连接字符串错误?,.net-core,entity-framework-core,.net Core,Entity Framework Core,我有一个.net core应用程序,我正试图使用EntityFrameworkCore来构建db,但当我这样做时: update-database 此错误显示为: Format of the initialization string does not conform to specification starting at index 0. 我已将连接字符串更改为标准格式,并尝试了此操作,因为我的主项目的程序集与我用于类的库不同,因此出现了一个错误: services.AddDbConte

我有一个.net core应用程序,我正试图使用EntityFrameworkCore来构建db,但当我这样做时:

update-database
此错误显示为:

Format of the initialization string does not conform to specification starting at index 0.
我已将连接字符串更改为标准格式,并尝试了此操作,因为我的主项目的程序集与我用于类的库不同,因此出现了一个错误:

services.AddDbContext<conn>(options => options.UseSqlServer("connname", b => b.MigrationsAssembly("conn")));


"ConnectionStrings": {
"FITMEConnection": "Server=foo;Database=fooname;Trusted_Connection=True"
},
我对此很生气,因为我搜索了这个错误,似乎很容易解决。我做错了什么?谢谢。

首先,您的appsettings.json文件应如下所示:

{
  "ConnectionStrings": {
    "FITMEConnection": "Server=foo;Database=foo;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*"
}
public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        var connectionString = Configuration.GetConnectionString("FITMEConnection"); // <-- Look at here

        services.AddDbContext<YourDbContext>(options => options.UseSqlServer(connectionString),b => b.MigrationsAssembly("MigrationAssemblyName")); 
   }
}
然后按以下步骤操作:

{
  "ConnectionStrings": {
    "FITMEConnection": "Server=foo;Database=foo;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*"
}
public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        var connectionString = Configuration.GetConnectionString("FITMEConnection"); // <-- Look at here

        services.AddDbContext<YourDbContext>(options => options.UseSqlServer(connectionString),b => b.MigrationsAssembly("MigrationAssemblyName")); 
   }
}

现在应该可以了

我现在遇到了这个错误:在建立到SQL Server的连接时发生了与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。提供程序:SQL网络接口,错误:26-定位指定的服务器/实例时出错,这意味着您的连接字符串无效!请再检查一下。@AntónioA你还收到问题吗?是的。我的连接字符串与您的相同mentioned@Ant奥尼亚问题还没有解决!可能是您缺少正确的服务器名称。您的计算机上安装了哪个版本的sql server?