在Linux Mint中无法从Monodevelop连接到MySQL数据库。

问题描述 投票:0回答:1

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

Unhandled Exception:
System.Data.SqlClient.SqlException (0x80131904): Snix_Connect (provider: SNI_PN7, error: 40 - SNI_ERROR_40)
Snix_Connect (provider: SNI_PN7, error: 40 - SNI_ERROR_40)
  at System.Data.SqlClient.SqlInternalConnectionTds..ctor (System.Data.ProviderBase.DbConnectionPoolIdentity identity, System.Data.SqlClient.SqlConnectionString connectionOptions, System.Data.SqlClient.SqlCredential credential, System.Object providerInfo, System.String newPassword, System.Security.SecureString newSecurePassword, System.Boolean redirectedUserInstance, System.Data.SqlClient.SqlConnectionString userConnectionOptions, System.Data.SqlClient.SessionData reconnectSessionData, System.Boolean applyTransientFaultHandling, System.String accessToken) [0x0018b] in <2ebdad619de74d1389f27154469c7cb1>:0 
  at System.Data.SqlClient.SqlConnectionFactory.CreateConnection (System.Data.Common.DbConnectionOptions options, System.Data.Common.DbConnectionPoolKey poolKey, System.Object poolGroupProviderInfo, System.Data.ProviderBase.DbConnectionPool pool, System.Data.Common.DbConnection owningConnection, System.Data.Common.DbConnectionOptions userOptions) [0x00159] in <2ebdad619de74d1389f27154469c7cb1>:0 

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

我尝试使用 连接器网络 但无济于事。

这就是代码。

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) { 

}
c# mysql linux monodevelop gtk#
1个回答
0
投票

我的问题是,我试图使用 System.Data.SqlClient 连接到MySQL数据库(它是针对微软SQL数据库的)。

按照这个 StackOverflow评论 我用的是 MySql.Data.MySqlClient 来连接。这种连接字符串的格式对我来说是有效的。

"server=localhost;" +
"port=3306;" +
"user id=root; " +
"password=[my password]; " +
"database=[the database I want to connect to]; " +
"SslMode=none"
© www.soinside.com 2019 - 2024. All rights reserved.