How do I change connection string for Update-Database ef migrations?

asp.net-core-2.0 dotnet-cli ef-migrations entity-framework-6

Question

I'm attempting to execute Update-Database, but the CLI is looking at the incorrect connection string when I try to provide it. Two connection strings may be found in my appsettings.json file:

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "ConnectionStrings": {
    "LocalWindows": "data source=.\\SQLEXPRESS;initial catalog=Intranet;persist security info=True;integrated security=true;",
    "AzureDevelopment": "Server=tcp:en..."
  }
}

Update-Database always uses the AzureDevelopment key when I execute it. I can update the right database if I transfer the LocalWindows connectionstring to AzureDevelopment's value. Additionally, if I remove AzureDevelopment but retain LocalWindows in the following format:

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "ConnectionStrings": {
    "LocalWindows": "data source=.\\SQLEXPRESS;initial catalog=Intranet;persist security info=True;integrated security=true;"
  }
}

I get:

Value cannot be null.
Parameter name: connectionString

I can no longer modify the key or provide the connection string as a parameter, thus it seems that at some time the CLI decided to utilise the AzureDevelopment string.

How does the migrations CLI know which connection string to use is my question. Is the string detected using startup settings that use some reflection magic? I can only find information online about executing Update-Database when specifying the project. The CLI no longer supports the -ConnectionString and -ConnectionStringName arguments that they formerly did.

1
3
1/24/2018 9:38:29 PM

Accepted Answer

ZZZ_tmp
5
2/15/2018 4:32:54 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow