我有个有趣的问题。我有一个数据连接器,我可以通过它对数据库执行插入和更新命令。问题是,有时一切运行正常,我的查询被插入,但有时ExecuteNonQuery方法只是冻结,我的数据连接器只是停止,它不会抛出任何异常,也不会抛出任何超时。这里有一个代码片段:
OdbcCommand insertCommand = dbConnection.CreateCommand();
insertCommand.CommandText = @"INSERT INTO `table`
(name, creation, modified, modified_by)
VALUES (
?, ?, ?, ?)";
insertCommand.Parameters.AddWithValue("@name", operation.ExternalProductionOrderLineOperationId);
insertCommand.Parameters.AddWithValue("@produced_qty", Convert.ToDecimal(operation.Quantity));
insertCommand.Parameters.AddWithValue("@product_operation_type", productionOrder.ProductOperationType);
insertCommand.Parameters.AddWithValue("@product_articulus", productionOrder.ProductArticulus);
_logger.LogInformation("Operacija paruosta exportinimui!"); <----------- THIS IS THE PLACE, sometimes it runs okey, sometimes it freezes
try
{
var n = insertCommand.ExecuteNonQuery();
if (n != 0)
{
await UpdateProductionOrderLineOperation(productionOrder, operation, true);
_logger.LogInformation("operation nr: {x} exported", counter);
}
else
{
_logger.LogInformation("operation nr: {x} failed to export");
}
}
catch (InvalidOperationException e)
{
_logger.LogInformation("InvalidOperationException: {x}", e.ToString());
}
catch (Exception e)
{
_logger.LogInformation("Exception: {x}", e.ToString());
}
}
catch (OdbcException e)
{
_logger.LogInformation("OdbcException: {x}", e.ToString());
}
catch (Exception e)
{
_logger.LogInformation("Exception: {x}", e.ToString());
}发布于 2021-04-12 04:51:39
将这行代码放在使用block..maybe中可以解决这个问题
var n= insertCommand.ExecuteNonQuery();
发布于 2021-04-12 09:49:59
将try块放在OdbcCommand之上,或者更好地将其放在打开连接的位置。因为你遇到的错误是在任何异常处理之前发生的,这就是应用程序失败的原因。
https://stackoverflow.com/questions/67049911
复制相似问题