ConnectionString无法正确读取-EF Core [英] ConnectionString not read properly - EF Core

查看:245
本文介绍了ConnectionString无法正确读取-EF Core的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EF Core连接到MySQL数据库。从1.0升级到1.1之后,似乎无法正确读取我的连接字符串。这是我的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
}
}
}

我正在初始化这样的DBContext:

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

//确保数据库创建
context = new Entities(optionsBuilder.Options);

似乎用一些默认值代替了主机名:

 无法连接到任何指定的MySQL主机。 
发生一个或多个错误。 (请求的地址在其上下文255.255.255.255:3306中无效)

请求的地址在其上下文255.255.255.255:3306

这是连接字符串:

  server = mmocstagingdb.australiasoutheast.cloudapp.azure.com;用户ID = root;密码= root;数据库= root;转换零日期时间= True; SSL模式=无 

(用用户名,密码和数据库值替代) TestSettings 是值得的,字段 ConnectionString



有人有什么想法吗?



PS



我认为这个问题有些相关: MissingMethodException DbSet .ToList



我最近已更新到.NET Core 1.1,并遇到与上述文章相同的错误。我使用接受的答案解决了它。但是,现在遇到了这个问题。

解决方案

此处令人尴尬的答案,但如果有人遇到此神秘错误消息,请发布。 / p>

事实证明主机无法访问,因为我之前曾在Azure上停止过服务器并忘记了。



但显然,如果主机不可访问,则会显示该主机尝试连接到255.255.255.255:3306 ...,这导致我误以为连接字符串未正确传递。


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.

解决方案

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.

这篇关于ConnectionString无法正确读取-EF Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆