From ORM Profiler running my ADO code
Exception type: System.Data.SqlClient.SqlException
Message: A severe error occurred on the current command. The results, if any, should be discarded.
Operation cancelled by user.
Stack-trace:
at System.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__180_0(Task`1 result)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at SD.Tools.OrmProfiler.Interceptor.ProfilerDbCommand.<ExecuteDbDataReaderAsync>d__13.MoveNext()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
at System.Threading.ExecutionContext.Run(ExecutionContext, ContextCallback, Object, Boolean)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run()
at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(Action, Boolean, Task&)
at System.Threading.Tasks.Task.FinishContinuations()
at System.Threading.Tasks.Task.Finish(Boolean)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task&)
at System.Threading.Tasks.Task.ExecuteEntry(Boolean)
at System.Threading.Tasks.ThreadPoolTaskScheduler.TryExecuteTaskInline(Task, Boolean)
at System.Threading.Tasks.TaskScheduler.TryRunInline(Task, Boolean)
at System.Threading.Tasks.TaskContinuation.InlineIfPossibleOrElseQueue(Task, Boolean)
at System.Threading.Tasks.Task.FinishContinuations()
at System.Threading.Tasks.Task.Finish(Boolean)
at System.Threading.Tasks.Task`1.TrySetException(Object)
at System.Threading.Tasks.UnwrapPromise`1.TrySetFromTask(Task, Boolean)
at System.Threading.Tasks.UnwrapPromise`1.ProcessInnerTask(Task)
at System.Threading.Tasks.UnwrapPromise`1.ProcessCompletedOuterTask(Task)
at System.Threading.Tasks.UnwrapPromise`1.Invoke(Task)
at System.Threading.Tasks.Task.FinishContinuations()
at System.Threading.Tasks.Task.Finish(Boolean)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task&)
at System.Threading.Tasks.Task.ExecuteEntry(Boolean)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
You can also see it running this in LinqPad (based off https://dotnetfiddle.net/o8c20l)
var w = new Stopwatch();
var con = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True;");
con.GetType().AssemblyQualifiedName.Dump();
await con.OpenAsync();
var ts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
var command = con.CreateCommand();
command.CommandText = "WAITFOR DELAY '00:01'";
try
{
w.Start();
await command.ExecuteReaderAsync(ts.Token);
}
catch (SqlException e)
{
w.Stop();
Console.WriteLine("Cancelled:" + w.Elapsed);
Console.WriteLine("Cancelled:" + e);
}