[英]Running Visual Studio 2019 .net web app in docker can't connect to external MySql server
I built a web app in Visual Studio 2019 .net that runs fine when hosted in IIS. The web app connects to a MySql server on my Synology NAS.我在 Visual Studio 2019 .net 中构建了一个 web 应用程序,当托管在 IIS 中时运行良好。web 应用程序连接到我的 Synology NAS 上的 MySql 服务器。 I want to build a docker image for it to move it to the synology server, but when I try to run the docker image created by Visual Studio I receive the following error when playing the image:我想为它构建一个 docker 图像以将其移动到 synology 服务器,但是当我尝试运行 Visual Studio 创建的 docker 图像时,我在播放图像时收到以下错误:
Server Error in '/' Application.
Unable to find the requested .Net Framework Data Provider. It may not be installed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.]
System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1326077
System.Web.UI.WebControls.SqlDataSource.GetDbProviderFactorySecure() +35
System.Web.UI.WebControls.SqlDataSource.CreateConnection(String connectionString) +15
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +140
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +389
System.Web.UI.WebControls.ListControl.PerformSelect() +44
System.Web.UI.Control.DataBindChildren() +248
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +195
System.Web.UI.Control.DataBindChildren() +248
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +195
System.Web.UI.Control.DataBindChildren() +248
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +195
System.Web.UI.Control.DataBindChildren() +248
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +195
System.Web.UI.WebControls.FormView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2704
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +97
System.Web.UI.WebControls.FormView.PerformDataBinding(IEnumerable data) +17
System.Web.UI.WebControls.FormView.EnsureDataBound() +198
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +106
System.Web.UI.Control.EnsureChildControls() +107
System.Web.UI.Control.PreRenderRecursiveInternal() +58
System.Web.UI.Control.PreRenderRecursiveInternal() +227
System.Web.UI.Control.PreRenderRecursiveInternal() +227
System.Web.UI.Control.PreRenderRecursiveInternal() +227
System.Web.UI.Control.PreRenderRecursiveInternal() +227
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3671
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4494.0
I have tried to install all of the MySql connectors but still can't get it to work.我已尝试安装所有 MySql 连接器,但仍然无法正常工作。 I am very new to docker. As in I have no clue what I am doing.我是 docker 的新手。因为我不知道自己在做什么。 I can get the app to run it just errors out when it goes to a page that tries to connect to the DB.我可以让应用程序运行它,只是在它转到尝试连接到数据库的页面时出错。
First, please confirm whether you have installed the mysql.net connector .首先请确认您是否安装了mysql.net连接器。 If not, install it.如果没有,请安装它。
If the installation of mysql.net connector does not work, this may be the case:如果安装 mysql.net connector 不起作用,可能是这种情况:
If the provider is not registered in one of that files the reported error is thrown.如果提供者未在其中一个文件中注册,则会抛出报告的错误。
Please change the following configuration in asp.net web.config like this:请像这样更改 asp.net web.config 中的以下配置:
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.DataAccess.Client" />
<add name="Oracle Data Provider for .NET"
invariant="Oracle.DataAccess.Client"
description="Oracle Data Provider for .NET"
type="Oracle.DataAccess.Client.OracleClientFactory,
Oracle.DataAccess,
Version=2.111.7.20,
Culture=neutral,
PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
I think I finally figured it out.我想我终于明白了。 I was using the Server explorer Data Connections to create the MySql connections, but docker does not like this.我使用服务器资源管理器数据连接创建 MySql 连接,但 docker 不喜欢这样。 So I changed everything to c# code data connections and it is now working in docker.所以我将所有内容更改为 c# 代码数据连接,它现在在 docker 中工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.