title: The certificate chain was issued by an authority that is not trusted
body: <p>I studied <a href="https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dbcontext-creation" rel="noreferrer">the help here on upgrading to aspnetcore 2.1.0</a></p>
  
  <p>My database is SQLExpress 2016SP1</p>
  
  <p>I am able to add a migration but when I issue </p>
  
  <pre><code>update-database
  </code></pre>
  
  <p>at the Package Manager Console, I get an error</p>
  
  <blockquote>
    <p>A connection was successfully established with the server, but then an error occurred during the login process.<br>
    (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)</p>
  </blockquote>
  
  <p>The connection string is of the form </p>
  
  <pre><code>   Server="Server=myserver;Initial Catalog=mydatabase;Trusted_Connection=True;MultipleActiveResultSets=true
  </code></pre>
  
  <p>The <code>DbContext</code> is</p>
  
  <pre><code>public class ApiDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApiDbContext(DbContextOptions&lt;ApiDbContext&gt; options)
          : base(options)
      {
      }
  }
  </code></pre>
  
  <p>The Context Factory is</p>
  
  <pre><code>public class MyContextFactory : IDesignTimeDbContextFactory&lt;ApiDbContext&gt;
  {
      public ApiDbContext CreateDbContext(string[] args)
      {
          var optionsBuilder = new DbContextOptionsBuilder&lt;ApiDbContext&gt;();
          var builder = new ConfigurationBuilder();
          builder.AddJsonFile("appsettings.json");
          var config = builder.Build();
          var connectionString = config.GetConnectionString("MyDatabase");
          optionsBuilder.UseSqlServer(connectionString);
          return new ApiDbContext(optionsBuilder.Options);
      }
  }
  </code></pre>
  
  <p>[Update]</p>
  
  <p>If I hard code the connection string inside the implementation of  IDesignTimeDbContextFactory  then I can run the migrations</p>
  
  <pre><code>public class MyContextFactory : IDesignTimeDbContextFactory&lt;ApiDbContext&gt;
  {
      public ApiDbContext CreateDbContext(string[] args)
      {
          var optionsBuilder = new DbContextOptionsBuilder&lt;ApiDbContext&gt;();
          var connectionString =    "Server=myserver;Initial Catalog=mydatabase;Trusted_Connection=True;MultipleActiveResultSets=true";
          optionsBuilder.UseSqlServer(connectionString);
          return new ApiDbContext(optionsBuilder.Options);
      }
  }
  </code></pre>
  
  <p>Hard coding the connection string is not desirable so I would like a better answer.</p>
  
  <p>I am unclear as to why the implementation of  IDesignTimeDbContextFactory is needed.  (my migration does fail without it )</p>
  
  <p>I have updated my Startup.cs and Progam.cs to match those of a newly generated program where the implementation is not needed.</p>
  
  <pre><code> public class Program
   {
     public static void Main(string[] args)
      {
          CreateWebHostBuilder(args).Build().Run();
      }
  
      public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;
          WebHost.CreateDefaultBuilder(args)
              .UseStartup&lt;Startup&gt;();
  }
  
  public class Startup
  {
      public Startup(IConfiguration configuration)
      {
          Configuration = configuration;
      }
  
      public IConfiguration Configuration { get; }
  
      // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
          services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
          {
              options.CheckConsentNeeded = context =&gt; true;
              options.MinimumSameSitePolicy = SameSiteMode.None;
          });
  
          services.AddDbContext&lt;ApiDbContext&gt;(options =&gt;
              options.UseSqlServer(
                  Configuration.GetConnectionString("MyDatabase")));
          services.AddDefaultIdentity&lt;IdentityUser&gt;()
              .AddEntityFrameworkStores&lt;ApiDbContext&gt;();
  </code></pre>
  
  <p>services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
          }</p>
  
  <pre><code>    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
              app.UseDatabaseErrorPage();
  
          }
          else
          {
              app.UseExceptionHandler("/Error");
              app.UseHsts();
          }
  
          app.UseHttpsRedirection();
          app.UseStaticFiles();
          app.UseCookiePolicy();
          app.UseAuthentication();
          app.UseMvc();
      }
  }
  </code></pre>
  
  <p>[Update]</p>
  
  <p>I updated to VS2017 version 15.7.3.
  When I went to repeat the problem and create the first migration, PM displayed the message</p>
  
  <pre><code>The configuration file 'appsettings.json' was not found and is not optional
  </code></pre>
  
  <p>When I marked this file copy always then both the add-migration and the update-database worked.</p>