如何查看System.Data.SqlClient中是否固定了"Invalid Operation, Erro



在高负载时,我们的应用程序随机抛出这个错误:

System.Data.SqlClient.SqlConnection.GetOpenTdsConnection
outerType
System.AggregateException
outerMessage
A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.
innermostType
System.InvalidOperationException
innermostMessage
Invalid operation. The connection is closed

我查看了一下,看起来这个问题在Microsoft.Data.SQLClient上是固定的

我们的代码来自旧世界,仍然使用System.Data.SqlClient.是否有办法知道同样的问题是否存在于System.Data.SqlClient并在新版本中修复?或者我们将不得不使用Microsoft.Data.SQLClient?(我们之前尝试过Microsoft.Data.SqlClient,但存在行为差异)

如果你正在使用任务你可以做以下尝试我不确定你会得到你想要的所有信息但是你会得到更多关于未处理异常的信息

public static void LogExceptions(this Task task)
{
task.ContinueWith( t =>
{
var aggException = t.Exception.Flatten();
foreach(var exception in aggException.InnerExceptions)
LogException(exception);
}, 
TaskContinuationOptions.OnlyOnFaulted);
}

你可以在

下面加上like
Task.Factory.StartNew( () => 
{ 
// Do your work...
}).LogExceptions();

或者您可以使用TaskScheduler.UnobservedTaskException来获取任务异常,而任务异常不会被观察到。

有关更多信息,请参阅以下链接

等待任务或访问其exception属性时未观察到Task's异常。因此,未被观察到的异常是

查找未观察到"A Task's"异常的原因…

最新更新