【问题标题】:Cannot connect to MySQL database from Monodevelop in Linux Mint无法从 Linux Mint 中的 Monodevelop 连接到 MySQL 数据库
【发布时间】:2020-08-25 07:40:06
【问题描述】:

我无法从 C# 连接到 MySQL 数据库。在尝试运行可执行文件时,它会吐出这个错误(这是它的开始):

未处理的异常: System.Data.SqlClient.SqlException (0x80131904):Snix_Connect(提供者:SNI_PN7,错误:40 - SNI_ERROR_40) Snix_Connect(提供者:SNI_PN7,错误:40 - SNI_ERROR_40) 在 System.Data.SqlClient.SqlInternalConnectionTds..ctor (System.Data.ProviderBase.DbConnectionPoolIdentity 身份,System.Data.SqlClient.SqlConnectionString connectionOptions,System.Data.SqlClient.SqlCredential 凭据,System.Object providerInfo,System.String newPassword,系统.Security.SecureString newSecurePassword, System.Boolean redirectedUserInstance, System.Data.SqlClient.SqlConnectionString userConnectionOptions, System.Data.SqlClient.SessionData reconnectSessionData, System.Boolean applyTransientFaultHandling, System.String accessToken) [0x0018b] in :0 在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection (System.Data.Common.DbConnectionOptions 选项,System.Data.Common.DbConnectionPoolKey poolKey,System.Object poolGroupProviderInfo,System.Data.ProviderBase.DbConnectionPool 池,System.Data.Common.DbConnection owningConnection, System.Data.Common.DbConnectionOptions userOptions) [0x00159] in :0

我可以很好地从 MySQL Workbench 连接到数据库。

我尝试使用Connector/Net,但无济于事。

这是代码:

dbCon = new SqlConnection(
    "Data Source=192.168.0.104, 3306; " +
    "Initial Catalog=Mundus; " + // Mundus is the database that I am trying to connect to
    "User ID=root;" + 
    "Password=[password that I use];"
);

dbCon.Open(); // from here it breaks
using(dbCon) { 
            
}

【问题讨论】:

  • System.Data.SqlClient 用于 Microsoft SQL Server,而不是 MySQL。切换到Connector/Net时出现什么错误?
  • @LexLi 非常感谢,我是个白痴。我没有意识到System.Data.SqlClient 是用于 Microsoft SQL 而不是 MySQL。我将用解决方案更新帖子。我对连接器/网络的问题是我收到了一堆程序集参考错误csharp Program.cs(1,7): error CS0246: The type or namespace name `Gtk' could not be found. Are you missing an assembly reference? Program.cs(2,14): error CS0234: The type or namespace name `Data' does not exist in the namespace `Mundus'. Are you missing an assembly reference?
  • 找到解决方案后,将其作为答案发布并接受。对于其他问题,请提出新问题。

标签: c# mysql linux monodevelop gtk#


【解决方案1】:

我的问题是我试图使用System.Data.SqlClient 连接到 MySQL 数据库(它适用于 Microsoft SQL 数据库)。

按照这个StackOverflow comment 我使用MySql.Data.MySqlClient 进行连接。这种格式的连接字符串对我有用:

"server=localhost;" +
"port=3306;" +
"user id=root; " +
"password=[my password]; " +
"database=[the database I want to connect to]; " +
"SslMode=none"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 2019-04-11
    • 2016-09-30
    • 2010-12-16
    • 1970-01-01
    • 2020-04-08
    • 2016-12-03
    相关资源
    最近更新 更多