The first query SELECT TOP 1 name FROM SiteMast... is issued using SqlCommand.ExecuteReader.
The third query exec sp_executesql N'SELECT n.Nam... is issued using SqlCommand.ExecuteReaderAsync, which should be the same.
I am pretty certain the async vs blocking is not the factor here - tested on a small sample:
using System;
using System.Data.SqlClient;
using System.Threading.Tasks;
namespace sql
{
class Program
{
static void Main(string[] args)
{
Sync();
Async().GetAwaiter().GetResult();
}
private static void Sync()
{
using (var c = new SqlConnection("server=localhost;database=test;trusted_connection=true"))
{
c.Open();
using (var cmd = c.CreateCommand())
{
cmd.CommandText = "SELECT Namespace,ClientId FROM Client";
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine($"{reader.GetString(0)}\t{reader.GetInt32(1)}");
}
}
}
}
}
private static async Task Async()
{
using (var c = new SqlConnection("server=localhost;database=dftest;uid=***;pwd=***"))
{
await c.OpenAsync();
using (var cmd = c.CreateCommand())
{
cmd.CommandText = "SELECT Namespace,ClientId FROM Client";
using (var reader = await cmd.ExecuteReaderAsync())
{
while (await reader.ReadAsync())
{
Console.WriteLine($"{reader.GetString(0)}\t{reader.GetInt32(1)}");
}
}
}
}
}
}
}
This code generates two SQL:BatchCompleted events.
My question - what causes some ADO.NET queries to be reported as SQL:BatchCompleted and some as RPC:Completed?
