c# - 从 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
解决方案
错误在您的连接字符串中。上面写着:
server=localhost;port3306;database=CountryDatabase;user=uzishan;password=mario1234
第二个组成部分应该是:
port=3306;
或者你可以完全放弃它,因为它是 MySQL 的默认设置。
推荐阅读
- r - 如何在 R 中同时遍历一个字符串向量和另一个数字向量?
- javascript - 如何避免使用“杀
" 每次收到错误命令:听 EADDRINUSE nodeJS? - vuejs2 - 如何在 vue-router 中使用 axios
- php - Laravel 控制器如果条件取决于输入文件
- python - 借助字典更正字符串中单词的拼写?
- php - 如果购物车中有 4 件商品,Woocommerce 不会显示弹出窗口
- c++ - 重构唯一函数具有不同参数的地方
- javascript - Uncaught SyntaxError: Unexpected token & 由于“错误
- c++ - QT QML 无法正确显示
- android - 从 URI 获取图像路径时出现空指针异常错误