我通过 .NET 连接器(6.8.3)广泛使用 MySQL服务器(5.6)数据库。出于性能原因,所有表都是使用 MyISAM 引擎创建的。我只有一个进程,一个线程按顺序访问数据库,因此不需要事务和并发。
请注意:这不太可能是超时配置问题,因为我的查询很简单。我确实阅读了所有与超时相关的问题(链接如下)。当然,我可能错了,但只是说"增加net_write_timeout参数"没有解释为什么它在这里可能是相关的不是答案。
我的一些表是在程序执行期间动态创建的,所以我在第一次使用习惯用法时使用创建,使用以下方法检查表是否存在:
private bool TableExists(Space baseSpace, Space extendedSpace)
{
var tableName = GenerateTableName(baseSpace, extendedSpace);
var sqlConnection = this.connectionPool.Take();
this.existsCommand.Connection = sqlConnection;
this.existsCommand.Parameters["@tableName"].Value = tableName.Trim('`');
var result = existsCommand.ExecuteScalar() as long?;
this.connectionPool.Putback(sqlConnection);
return result == 1;
}
existsCommand
内的查询如下(为了便于阅读,此处分为两行):
SELECT COUNT(*) FROM information_schema.tables
WHERE table_schema = 'my_schema' AND table_name = @tableName
this.existsCommand.Parameters["@tableName"].Value
变量的值包含表的正确名称,在这种情况下已存在("sample_matches_A_to_A_x"
)。
this.connectionPool.Take()
方法返回符合以下谓词的可用连接集合中的第一个MySqlConnection
对象:
private bool IsAvailable(MySqlConnection connection)
{
return connection != null
&& connection.State == System.Data.ConnectionState.Open;
}
通常这种方法可以正常工作几个小时,然后在这一行突然发生异常:
var result = existsCommand.ExecuteScalar() as long?;
具有以下内容:
命令执行期间遇到致命错误
堆栈追踪:
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteScalar()
在C:... \ SampleMatchesMySqlTable.cs中的implementation.SampleMatchesMySqlTable.TableExists(Space baseSpace,Space extendedSpace):第168行
内部异常:
无法将数据写入传输连接:软件导致连接中止。
内部异常:
软件导致连接中止。
ErrorCode等于10053
且SocketErrorCode为System.Net.Sockets.SocketError.ConnectionAborted
最内层异常的堆栈跟踪:
at System.Net.Sockets.Socket.Send(Byte [] buffer,Int32 offset,Int32 size,SocketFlags socketFlags)
在System.Net.Sockets.NetworkStream.Write(Byte []缓冲区,Int32偏移量,Int32大小)
我已经审核了以下可能的副本,不幸的是,除了一个之外,它们似乎并不相关:
SHOW TABLES encountered Fatal error encountered during command execution
不幸的是,它没有提供足够的信息来判断它是否完全重复,也没有得到答复。
与超时问题有关。我的查询很小,只返回一个整数,并在包含20个其他表格的元表中搜索表。
Fatal error encountered during command execution. in C# when i use Insert Into
https://stackoverflow.com/questions/7895178/fatal-error-in-mysql
MySQL Exception - Fatal Error Encountered During Data Read
Fatal error encountered during data read
Fatal error causing timeout -mysql
ADO.Net Entity framework, Fatal error encountered during data read
有关读取结果集的不同错误:
Fatal error encountered during command execution
语法错误和连接字符串问题:
Mysql Fatal error encountered during command execution
fatal error encountered during execution... during update
Fatal error encountered during command execution
fatal error encountered during command execution during update
fatal error encountered during command execution c# mysql
Fatal error encountered during command execution with a mySQL INSERT
I have Fatal error encountered during command execution
MySql exception was unhandled - Fatal error encountered during command execution
Fatal Error Encounter During Command Execution MySQL VB
"Fatal error encountered during command execution." mysql-connector .net
"Fatal error encountered during command execution."
创建视图: "fatal error encountered during command execution" when trying to add a view from MySQL DB
阅读CSV文件:
Fatal error encountered during command execution while importing from csv to mysql
答案 0 :(得分:0)
我最终修改了IsAvailable
方法,如下所示:
private bool IsAvailable(MySqlConnection connection)
{
var result = false;
try
{
if (connection != null)
{
result = connection.Ping();
}
}
catch (Exception e)
{
Console.WriteLine("Ping exception: " + e.Message);
}
return result && connection.State == System.Data.ConnectionState.Open;
}
.Ping
调用在验证连接状态及其属性方面似乎更好,尽管它的记录很差。从其他一些来源我同时阅读:
另一种方法是运行SELECT 1 FROM DUAL
之类的简单查询,而不是调用Ping
。
此外,有时似乎有DataReader
,即使它被处理(所有内容都使用using
语句实现),仍然会在短时间内连接到连接。因此,我已将条件修改为:
if (connection != null && connection.State == ConnectionState.Open)
只要State
附加DataReader
属性,Open
属性就会有Executing
值,因此另外验证它的{{1}}是否在开始时有效这里很好。