PageAsyncTask Problem


M

mmorrison93

I'm trying to set up a test asynchronously executing page that will
call a database stored procedure and then simply add text to a Label
control name mylabel However after executing the BeginEventHandler,
the EndEventHandler is not called and I have no idea why any help is
appreciated. My .aspx file is minimal the only thing on the page is my
label.

In my code behind file i have the following:

protected void Page_Load(object sender, System.EventArgs e)
{
PageAsyncTask task = new PageAsyncTask(
new BeginEventHandler(BeginTask),
new EndEventHandler(EndTask),
null,
null);

RegisterAsyncTask(task);
Page.ExecuteRegisteredAsyncTasks();
}

public IAsyncResult BeginTask(object sender, EventArgs e,
AsyncCallback cb, object state)
{
using (SqlConnection cn = new
SqlConnection(WebConfigurationManager.ConnectionString.
["conn"].ConnectionString))
{
cmd = new SqlCommand("sp_AnheiserBusch_GetWeeks", cn);
cmd.CommandType = CommandType.StoredProcedure;
IAsyncResult ar;

try
{
cn.Open();
ar = cmd.BeginExecuteReader(cb, state);
}
finally
{
cn.Close();
}

return ar;
}
}

public void EndTask(IAsyncResult ar)
{
mylabel.Text = "EndTask";
}

Thanks.
 
Ad

Advertisements

B

bruce barker

as you close the connection right after starting the async query, it should
throw an error. you can not close the connection until the results are read
with:

cmd.EndExecuteReader()

which should be called in the end handler.

-- bruce (sqlwork.com)
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top