What should you do to ensure that the application continues to execute while cmd is executing?

You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET. The application connects to a Microsoft SQL Server 2005 database.

The connection string of the application is defined in the following manner.

"Server=Prod;Database=WingtipToys;Integrated Security=SSPI;Asynchronous Processing=true"

The application contains the following code segment. (Line numbers are included for reference only.)

01 protected void UpdateData(SqlCommand cmd) {
02 cmd.Connection.Open();
03
04 lblResult.Text = "Updating …";
05 }

The cmd object takes a long time to execute. You need to ensure that the application continues to execute while cmd is executing.

What should you do?

You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET. The application connects to a Microsoft SQL Server 2005 database.

The connection string of the application is defined in the following manner.

“Server=Prod;Database=WingtipToys;Integrated Security=SSPI;Asynchronous Processing=true”

The application contains the following code segment. (Line numbers are included for reference only.)

01 protected void UpdateData(SqlCommand cmd) {
02 cmd.Connection.Open();
03
04 lblResult.Text = “Updating …”;
05 }

The cmd object takes a long time to execute. You need to ensure that the application continues to execute while cmd is executing.

What should you do?

A.
Insert the following code segment at line 03.
cmd.BeginExecuteNonQuery(new AsyncCallback(UpdateComplete), cmd);
Add the following code segment.
private void UpdateComplete (IAsyncResult ar)
{
int count = (int)ar.AsyncState;
LogResults(count);
}

B.
Insert the following code segment at line 03.
cmd.BeginExecuteNonQuery(new AsyncCallback(UpdateComplete), cmd);
Add the following code segment.
private void UpdateComplete (IAsyncResult ar)
{
SqlCommand cmd = (SqlCommand)ar.AsyncState;
int count = cmd.EndExecuteNonQuery(ar);
LogResults(count);
}

C.
Insert the following code segment at line 03.
cmd.StatementCompleted += new StatementCompletedEventHandler(UpdateComplete);
cmd.ExecuteNonQuery();
Add the following code segment.
private void UpdateComplete (object sender, StatementCompletedEventArgs e)
{
int count = e.RecordCount;
LogResults(count);
}

D.
Insert the following code segment at line 03.
SqlNotificationRequest notification = new SqlNotificationRequest(“UpdateComplete”, “”, 10000);
cmd.Notification = notification;
cmd.ExecuteNonQuery();
Add the following code segment.
private void UpdateComplete(SqlNotificationRequest notice)
{
int count = int.Parse(notice.UserData);
LogResults(count);
}



Leave a Reply 0

Your email address will not be published. Required fields are marked *