l3utterfly
l3utterfly

Reputation: 2196

ConnectionString not read properly - EF Core

I'm using EF Core to connect to a MySQL database. Ever since upgrading from 1.0 to 1.1, my connection string does not seem to be read properly. Here is my project.json:

{
  "version": "1.0.0-*",

  "dependencies": {
    "MySql.Data": "7.0.6-IR31",
    "MySql.Data.EntityFrameworkCore": "7.0.6-IR31",
    "NETStandard.Library": "1.6.1"
  },

  "tools": {
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-*"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  }
}

I'm initialising a DBContext like this:

var optionsBuilder = new DbContextOptionsBuilder<Entities>();
optionsBuilder.UseMySQL(TestSettings.ConnectionString);

// Ensure database creation
context = new Entities(optionsBuilder.Options);

It seems to substitute some default value for the host name:

Unable to connect to any of the specified MySQL hosts.
One or more errors occurred. (The requested address is not valid in its context 255.255.255.255:3306)

The requested address is not valid in its context 255.255.255.255:3306

This is the connection string:

"server=mmocstagingdb.australiasoutheast.cloudapp.azure.com;user id=root;password=root;database=root;Convert Zero Datetime=True;SSL Mode=None"

(Username, password, and database values are substituted) For what it's worth, TestSettings is a static class with a static field ConnectionString

Anyone have any ideas?

P.S.

I think this question is somewhat related: MissingMethodException DbSet.ToList

I have updated to .NET Core 1.1 lately and ran into the same error as the mentioned post. I resolved it using the accepted answer. But now running into this problem.

Upvotes: 0

Views: 679

Answers (1)

l3utterfly
l3utterfly

Reputation: 2196

Embarrassing answer here, but posting in case someone else runs into this cryptic error message.

It turns out the host was inaccessible because I stopped the server on Azure before and forgot.

But apparently, if the host is inaccessible, the will show it trying to connect to 255.255.255.255:3306... which lead me down the wrong train of thought thinking the connection string was not passed in correctly.

Upvotes: 3

Related Questions