2

我遵循了这篇博客关于将 Net Core Web App 托管到 Linux Ubuntu 19 的教程,

https://www.hanselman.com/blog/PublishingAnASPNETCoreWebsiteToAHeapLinuxVMHost.aspx

但托管后,我在同一台服务器上运行 mysql 数据库,但我的网站无法加载任何数据。关于我应该如何更改我的 ConnectionString 的任何帮助?

"MySQLConnection": "Server=127.0.0.1;Database=database_name;User=user_name;Password=password_correct;CharSet=utf8mb4_unicode_520_ci;SslMode=none;"

"MySQLConnection": "Server=127.0.0.1:8080;Database=database_name;User=user_name;Password=password_correct;CharSet=utf8mb4_unicode_520_ci;SslMode=none;"

这是我的启动代码:

services.AddDbContextPool<ApplicationDbContext>(
    options => options.UseMySql(Configuration.GetConnectionString("MySQLConnection"), 
                mySqlOptions =>
                {
                    mySqlOptions.ServerVersion(new Version(5, 7, 24), ServerType.MySql);
                    mySqlOptions.DisableBackslashEscaping();
                }
));

它运行良好,但不会连接到数据库。请协助。

得到错误:

C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs 中的 MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancelToken),第 326 行

MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, 
ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs
MySqlConnector.Core.ConnectionPool.GetSessionAsync(MySqlConnection connection, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ConnectionPool.cs
MySqlConnector.Core.ConnectionPool.GetSessionAsync(MySqlConnection connection, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ConnectionPool.cs
MySql.Data.MySqlClient.MySqlConnection.CreateSessionAsync(Nullable<IOBehavior> ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs
MySql.Data.MySqlClient.MySqlConnection.OpenAsync(Nullable<IOBehavior> ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs
MySql.Data.MySqlClient.MySqlConnection.Open() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs
Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(bool errorsExpected)
Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(bool errorsExpected)
Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable<T>+Enumerator.BufferlessMoveNext(DbContext _, bool buffer)
Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlExecutionStrategy.Execute<TState, TResult>(TState state, Func<DbContext, TState, TResult> operation, Func<DbContext, TState, ExecutionResult<TResult>> verifySucceeded)
Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable<T>+Enumerator.MoveNext()
Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider._TrackEntities<TOut, TIn>(IEnumerable<TOut> results, QueryContext queryContext, IList<EntityTrackingInfo> entityTrackingInfos, IList<Func<TIn, object>> entityAccessors)+MoveNext()
Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider+ExceptionInterceptor<T>+EnumeratorExceptionInterceptor.MoveNext()
Microsoft.AspNetCore.Mvc.Rendering.MultiSelectList.GetListItemsWithValueField()
Microsoft.AspNetCore.Mvc.Rendering.MultiSelectList.GetListItems()
Microsoft.AspNetCore.Mvc.Rendering.MultiSelectList.GetEnumerator()
System.Collections.Generic.List<T>.AddEnumerable(IEnumerable<T> enumerable)
System.Linq.Enumerable.ToList<TSource>(IEnumerable<TSource> source)
Microsoft.AspNetCore.Mvc.ViewFeatures.DefaultHtmlGenerator.GenerateGroupsAndOptions(string optionLabel, IEnumerable<SelectListItem> selectList, ICollection<string> currentValues)
Microsoft.AspNetCore.Mvc.ViewFeatures.DefaultHtmlGenerator.GenerateSelect(ViewContext viewContext, ModelExplorer modelExplorer, string optionLabel, string expression, IEnumerable<SelectListItem> selectList, ICollection<string> currentValues, bool allowMultiple, object htmlAttributes)
Microsoft.AspNetCore.Mvc.TagHelpers.SelectTagHelper.Process(TagHelperContext context, TagHelperOutput output)
Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.RunAsync(TagHelperExecutionContext executionContext)
AspNetCore.Views_Appointments_BookAppointment.<ExecuteAsync>b__20_0() in C:\Users\User\source\repos\TPSolution\src\WebApplication\Frescar\Views\Appointments\BookAppointment.cshtml
Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext.GetChildContentAsync(bool useCachedResult, HtmlEncoder encoder)
Microsoft.AspNetCore.Mvc.TagHelpers.RenderAtEndOfFormTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.RunAsync(TagHelperExecutionContext executionContext)

注意:在使用 Visual Studio 进行开发时,它在我的 Windows 10 本地上使用 IIS 进行测试时运行良好。

4

0 回答 0