It's a client-side timeout, but not triggered by CommandTimeout. This is the error you get when your async command execution is aborted by a CancellationToken.
A severe error occurred on the current command. The results, if any, should be discarded. Operation cancelled by user." The SQL Error code is 0.
So whatever creates your CancellationToken is canceling the command. You can register a cancellation callback to examine the stack and see what code is causing the cancellation. eg
cancellationToken.Register(() =>
{
var st = new System.Diagnostics.StackTrace();
Console.WriteLine(st.ToString());
});
Here's a simple example:
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace SqlClientTest
{
class Program
{
static void Main(string[] args)
{
var ct = new CancellationTokenSource();
var task = Run(ct.Token);
task.Wait(20 * 1000);
ct.Cancel();
task.Wait();
}
static async Task Run(CancellationToken token)
{
var constr = @"server=localhost;database=tempdb;Integrated Security=true";
using (var con = new SqlConnection(constr))
{
con.Open();
var cmd = new SqlCommand("waitfor delay '00:05:00'", con);
try
{
await cmd.ExecuteNonQueryAsync(token);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
}
}