首页 > 解决方案 > 从 WebAPI 消费的 Net Core 2.0 Mysql 数据库(新手)

问题描述

因此,我尝试按照本指南将 MySQL 数据库链接到我的 Web 应用程序。https://www.c-sharpcorner.com/article/how-to-connect-mysql-with-asp-net-core/

问题是我在调试时遇到这些错误:

处理请求时发生未处理的异常。ArgumentException:不支持选项。参数名称:port3306;数据库

MySql.Data.MySqlClient.MySqlBaseConnectionStringBuilder.GetOption(string key)

WebApplication2.Models.CountryContext.GetConnection() in CountryContext.cs

             21.  return new MySqlConnection(ConnectionString);

WebApplication2.Models.CountryContext.GetAllCountries() in CountryContext.cs

          29.  using (MySqlConnection conn = GetConnection())

WebApplication2.Controllers.CountriesController.Index() in CountriesController.cs

             16.  return View(context.GetAllCountries());

在搜索了大约 8 小时后,我也无法弄清楚如何使这个基本数据库工作并使用网站上的数据。

我觉得我错过了一些非常愚蠢的东西......

这是完整应用程序的 git。 https://github.com/uzishan/TestWebAPI

标签: c#mysql

解决方案


错误在您的连接字符串中。上面写着:

server=localhost;port3306;database=CountryDatabase;user=uzishan;password=mario1234

第二个组成部分应该是:

port=3306;

或者你可以完全放弃它,因为它是 MySQL 的默认设置。


推荐阅读