I don't know what I might have done to cause this, but a await reader.ReadAsync()
is taking 8000 ms, compared to 2ms if I replace ReadAsync()
with Read()
in the same method
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = connectionString;
await conn.OpenAsync();
string cmdText = "SELECT * FROM images WHERE order_id = @OrderId";
using (SqlCommand cmd = new SqlCommand(cmdText, conn))
{
cmd.Parameters.Add("@OrderId", SqlDbType.UniqueIdentifier).Value = id;
using (var reader = await cmd.ExecuteReaderAsync())
{
if (!reader.HasRows) return null;
await reader.ReadAsync();
return (byte[])reader["image"];
}
}
}
Removed some of the method for readability
The varbinary in question is about 11MB in size. The actual query execution is still fast, it's just the read that's incredibly slow. Smaller varbinaries are fine.
The image
column is a FILESTREAM