簡體   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