【发布时间】:2020-01-09 11:49:52
【问题描述】:
我的应用程序由于此异常而崩溃:
Exception Info: System.NotSupportedException
at System.Net.Security._SslStream.ProcessRead(Byte[], Int32, Int32, System.Net.AsyncProtocolRequest)
at System.Net.Security.SslStream.Read(Byte[], Int32, Int32)
at MySql.Data.MySqlClient.TimedStream.Read(Byte[], Int32, Int32)
at MySql.Data.MySqlClient.MySqlStream.ReadFully(System.IO.Stream, Byte[], Int32, Int32)
at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32 ByRef, Int64 ByRef)
at MySql.Data.MySqlClient.Driver.GetResult(Int32, Int32 ByRef, Int64 ByRef)
at MySql.Data.MySqlClient.Driver.NextResult(Int32, Boolean)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlDataReader.Close()
at MySql.Data.MySqlClient.MySqlConnection.Close()
at MySql.Data.MySqlClient.MySqlConnection.Dispose(Boolean)
at MySql.Data.MySqlClient.MySqlConnection.Finalize()
我已经尝试升级到最新的框架,并下载了最新版本的 MySql.Data 文件。
这就是我的一种查询方法的样子。其他查询方法遵循相同的结构。
public static long InsertReturnInsertedAutoIncID(string queryStr, string[,] Parameters)
{
int attempts = 0;
do
{
try
{
attempts++;
long autoIncID;
using (MySqlConnection dbObj = new MySqlConnection(connectionToDBstring))
{
dbObj.Open();
using (MySqlCommand query = new MySqlCommand(queryStr, dbObj))
{
// Add parameters to query (as we don't want to concatinate)
for (int i = 0; i < Parameters.GetLength(0); i++)
{
query.Parameters.AddWithValue(Parameters[i, 0], Parameters[i, 1]);
}
query.ExecuteNonQuery();
autoIncID = query.LastInsertedId;
}
}
return autoIncID;
}
catch (Exception ex)
{
Logger.Log.Error(ex.ToString());
if (attempts >= maxAttempts)
{
return -1;
}
System.Threading.Thread.Sleep(200);
}
} while (true);
}
我的应用程序中运行着许多线程(任务)来查询数据库。没有使用锁,因为线程不应该被搁置太久。这个问题很少发生(比如每 7 天左右)。我希望这个异常根本不会发生,但是如果我可以忽略也可以的异常,那么我会重试查询。问题是这个异常导致我的应用程序停止工作(因为应用程序正在获取“应用程序已停止工作”窗口。)
【问题讨论】:
-
尝试将异常处理程序放在“使用”中。 using 有自己的处理程序,然后代码返回并且永远不会看到您的 while 循环。
-
嗨。我试图在两个“使用”块中产生异常。当发生异常时,下一个执行的行是 catch 块。这是正确的行为。因此,我不确定在“使用”块中添加异常处理程序有何帮助。
-
请发布 A) SHOW GLOBAL STATUS LIKE '%thread%'; 的 TEXT 结果和 B) 显示全局变量,例如 '%thread%';和 C) SHOW GLOBAL STATUS LIKE 'com_stmt%';