繁体   English   中英

在 docker 中运行 Visual Studio 2019 .net web 应用程序无法连接到外部 MySql 服务器

[英]Running Visual Studio 2019 .net web app in docker can't connect to external MySql server

我在 Visual Studio 2019 .net 中构建了一个 web 应用程序,当托管在 IIS 中时运行良好。web 应用程序连接到我的 Synology NAS 上的 MySql 服务器。 我想为它构建一个 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

我已尝试安装所有 MySql 连接器,但仍然无法正常工作。 我是 docker 的新手。因为我不知道自己在做什么。 我可以让应用程序运行它,只是在它转到尝试连接到数据库的页面时出错。

  1. 首先请确认您是否安装了mysql.net连接器 如果没有,请安装它。

  2. 如果安装 mysql.net connector 不起作用,可能是这种情况:

如果提供者未在其中一个文件中注册,则会抛出报告的错误。

请像这样更改 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>

我想我终于明白了。 我使用服务器资源管理器数据连接创建 MySql 连接,但 docker 不喜欢这样。 所以我将所有内容更改为 c# 代码数据连接,它现在在 docker 中工作。

暂无
暂无

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

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