【发布时间】: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#