简体   繁体   English

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

[英]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.我可以让应用程序运行它,只是在它转到尝试连接到数据库的页面时出错。

  1. First, please confirm whether you have installed the mysql.net connector .首先请确认您是否安装了mysql.net连接器 If not, install it.如果没有,请安装它。

  2. 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.

相关问题 C# and Docker - Can't connect to containerized MySQL server from containerized .NET Core 3.1 Web API - C# and Docker - Can't connect to containerized MySQL server from containerized .NET Core 3.1 Web API Visual Studio 2019“无法连接到 web 服务器‘IIS Express’” - Visual studio 2019 “Unable to connect to web server 'IIS Express'” 无法从运行在 docker 上的 .net 核心应用连接到 SQL Server express - Can't connect to SQL Server express from .net core app running on docker Visual Studio ADO .NET 无法连接到 mysql 数据库 - Visual Studio ADO .NET can't connect to mysql database 无法连接到 Visual Studio 2019 C# 中的 Oracle 数据库 - Can't connect to Oracle database in Visual Studio 2019 C# Visual Studio 正在运行,但本地主机无法连接 - visual studio is running, but localhost can't connect 无法使用 Visual Studio 2019 连接 MySQL 数据库 - Unable to connect with MySQL database with visual studio 2019 无法连接到Visual Studio中的MySQL数据库 - Can't connect to MySQL database in Visual Studio 将Visual Studio与Web服务器连接 - Connect Visual Studio with Web Server Visual Studio 2019 - Docker 4.1.1 - Web 添加容器编排后应用停止工作 - Visual Studio 2019 - Docker 4.1.1 - Web App Stops Working After Adding Container Orchestration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM