简体   繁体   English

在Docker上连接到MySql

[英]Connecting to MySql on Docker

I have an ASP.NET 5 Web API application which I have deployed on docker. 我有一个已部署在docker上的ASP.NET 5 Web API应用程序。 It connects to a MySql instance, also on docker. 它也连接到docker上的MySql实例。 I am using Entity Framework 6 to connect to the MySql database. 我正在使用Entity Framework 6连接到MySql数据库。 I have not referenced Entity Framework directly, but am using the MySql.Data.Entity package which internally uses Entity Framework 6. 我没有直接引用实体框架,但是正在使用内部使用实体框架6的MySql.Data.Entity包。

When I invoke the API, I get this error: 当我调用API时,出现以下错误:

Unable to determine the provider name for provider factory of type 'MySql.Data.MySqlClient.MySqlClientFactory' 无法确定类型为'MySql.Data.MySqlClient.MySqlClientFactory'的提供程序工厂的提供程序名称。

Outside docker, ie, on my windows machine, in Visual Studio 2015, I point my web API to the MySql instance on docker, and I can connect just fine. 在docker外部,即在Windows机器上的Visual Studio 2015中,我将Web API指向docker上的MySql实例,并且可以正常连接。 Inside docker, I get the error mentioned above. 在docker内部,我收到上述错误。

What could be wrong? 有什么事吗

I'm not an expert on ASP.NET, but doesn't your question translate to: 我不是ASP.NET的专家,但是您的问题不是翻译成:

If I run ASP.NET on Windows everything works fine, if I run it on Linux I get an exception. 如果我在Windows上运行ASP.NET,则一切正常,如果我在Linux上运行,则会出现异常。

?

I don't think this is a Docker issue and would rather investigate about issues / driver needs the Entity Framework has on Mono. 我认为这不是Docker问题,而是愿意调查Entity Framework在Mono上存在的问题/驱动程序需求。

The provider name is not being passed. 提供者名称未传递。 Prior to ASP.NET 5 the provider value could be set alongside connectionString in in the web.config. 在ASP.NET 5之前,可以在web.config中的connectionString旁边设置provider值。 This is no longer the case, as the connection string is just a string value in a json file with no extra properties. 情况不再如此,因为连接字符串只是json文件中的字符串值,没有额外的属性。

You need to set it programatically. 您需要以编程方式进行设置。 Here's an example , notably this part; 这是一个例子 ,特别是这部分。

SetProviderServices("MySql.Data.MySqlClient", new MySqlProviderServices());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM