c# - 无法连接到任何指定的 MySQL 主机?C# + Heroku + ClearDB
问题描述
我有一个托管在 Heroku 上的 Web API。它通过 Golang 程序提供来自 ClearDB 的数据。我有一个需要将数据插入到 ClearDB 的 C# .NET 脚本。我有这个想法在我的本地机器上工作,但是当我把所有东西都移到 heroku 上时,C# 部分停止了工作。
我已经成功连接 MySQL Workbench 8.0 和我的 Golang 程序本身。GO 程序可以成功连接、查询和提供数据。
我知道还有很多其他类似的问题,其中大多数似乎都可以通过连接字符串解决。我已经尝试了几乎所有可以将连接字符串串起来的不同方法。这是我上次尝试的(凭证已更改为随机字母):
connectionData = @"Server = eu-cd-steel-west-01.cleardb.net; Port = 3306; Database = heroku_555555555; Uid = b7039sldk253; Pwd = e3502ldks;";
当我运行这个时,我得到的错误发生了:
connection = new MySqlConnection(connectionData);
connection.Open();
错误:
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
---> System.InvalidOperationException: Sequence contains more than one matching element
at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings)
at MySql.Data.Common.StreamCreator.GetStream(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at DatabaseTesting.DataBaser.connect() in C:\Users\surf.user\source\repos\DatabaseTesting\DatabaseTesting\DataBaser.cs:line 38
我知道有 SSL 凭证和各种各样的东西,但我相信这并不重要,因为我不需要配置任何特殊的东西来连接工作台。要在 C# 上成功打开 ClearDB 连接,我还需要做些什么吗?
解决方案
我怀疑您在 Oracle 的 MySQL 连接器/NET 中遇到了这个已知错误:错误 97448。(我无法解析您在问题中提供的域名,但如果它解析为多个A
记录,则会触发错误。)
修复方法是卸载MySql.Data
NuGet 包并MySqlConnector
改为安装:https ://www.nuget.org/packages/MySqlConnector/
这支持与 MySql.Data 相同的 API,因此它应该是一个替代品。
推荐阅读
- html - 如何修复“Stray end tag head”。和“看到开始标签主体,但已打开相同类型的元素。” 在 HTML 中
- botframework - 如何修复 [err-client] Uncaught TypeError: Cannot create property 'firstName' on string 'one'
- agora.io - 一对一用户在agora视频通话期间无法看到对方
- php - 在 PHP 的未来版本中,与其类同名的方法将不再是构造函数;mPDF 有一个不推荐使用的构造函数
- java - 为什么这个 gson 函数会保存一个空白文件?
- python - 我在我的 django 模型中添加位置字段它显示错误
- django - 如何在 django 中设置 ftp
- dropwizard - 对 dropwizard 应用程序以及 BigtableClientMetrics 使用单个 dropwizard MetricRegistry
- google-app-engine - 来自 Google Cloud Storage 问题的 Google Cloud App Engine 下载对象
- php - (SQL)获取用户和朋友在2个不同表中的朋友