There is nothing worthy in an example that doesn't use the EndProcessRequest.
Try using SqlCommand's BeginExecuteReader in the Begin and EndExecuteReader in the EndProcessRequest.
Please indicate how to do this without hitting an exception.
Here is such an example:
public class MyAsync : IHttpAsyncHandler { ...
public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
{
... open with connectionString + ";Asynchronous Processing=true" ...
IAsyncResult asyncResult = sqlCmd.BeginExecuteReader(cb, context, CommandBehavior.CloseConnection);
// store our Command to be later retrieved by EndProcessRequest
context.Items.Add("sqlcmd", sqlCmd);
return asyncResult;
}
public void EndProcessRequest(IAsyncResult result)
{
// restore used Command
SqlCommand cmd = (SqlCommand)context.Items["cmd"];
// retrieve result
using (SqlDataReader reader = cmd.EndExecuteReader(result))
{
// do the one read to pull data
reader.Read();
// get image to call MakeThumbnail
byte[] imageBytes = (byte[])dr[0];
// Cache this handler response.
HttpCachePolicy c = context.Response.Cache;
c.SetCacheability(HttpCacheability.Public);
c.SetMaxAge(timeout);
context.Response.BinaryWrite(imageBytes);
context.Response.Flush();
}
}
}