首页 > 解决方案 > 在 MariaDB 10 上使用 Connector/NET 打开事务时出现语法错误

问题描述

我正在尝试将我的 Web 应用程序连接到 MariaDB 10 服务器。我已经在使用 MySQL Connector/NET 的版本 5 上毫无问题地做到了。在版本 10 中,当软件执行 BeginTransaction 时,我在执行查询之前收到错误。

IDbConnection dbConnection=new MySqlConnection(connectionString);
dbConnection.BeginTransaction();

这个错误很经典:

[MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1]
MySql.Data.MySqlClient.MySqlStream.ReadPacket() +384
MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) +379
MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) +119
MySql.Data.MySqlClient.MySqlDataReader.NextResult() +901
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +2308
MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() +133
MySql.Data.MySqlClient.MySqlConnection.BeginTransaction(IsolationLevel iso) +761
MySql.Data.MySqlClient.MySqlConnection.BeginDbTransaction(IsolationLevel isolationLevel) +19

我检查了连接器源代码,它似乎在执行时发生

cmd.CommandText = "BEGIN";
cmd.ExecuteNonQuery();

在这个文件中https://github.com/mysql/mysql-connector-net/blob/6.9/Source/MySql.Data/Connection.cs

我将这个问题作为 Connector/NET 的问题提交,但我收到了使用 HeidiSQL 执行“BEGIN”的相同错误,所以这可能是一个普遍问题。

它似乎连接到分隔符,但听起来很奇怪,因为它是连接器内部的东西,HeidiSQL 和我的软件,只需更改连接字符串,就可以在 MariaDB 5 上正常工作。

我可能是由于某些服务器配置?

标签: .netmariadbmysql-connector

解决方案


我们对原始连接器/NET 有很多问题,有一些众所周知的错误是您无法真正解决的,原始连接器背后的团队(如果有的话)似乎并不关心

我们最终切换到了很棒的开源MySqlConnector 。

它从头开始实现协议,修复了官方连接器中的大量已知错误(请参阅此处的底部)。

它还宣传了一些额外的功能,例如真正的异步功能等。

披露:我和我的团队与上述项目没有任何关系,我们只是因为官方项目中的错误而不得不切换,从那时起我们就是快乐的用户。


推荐阅读