O'Reilly logo

ADO.NET Cookbook by Bill Hamilton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.22. Querying Data Asynchronously with Message Queuing

Problem

You want to asynchronously retrieve data from a system that is not always connected.

Solution

You must:

  • Use message queuing to construct and send a data request from the client.

  • Access and process the requesting message at the server.

  • Compose and send a response message containing the result set to the client.

  • Retrieve the response at the client and deserialize it into a DataSet.

The sample code contains three event handlers:

Send Button.Click

Checks if the query message queue exists and creates it if necessary. A MessageQueue object is created to access the queue. A message is sent to the queue containing the CustomerID which the user wants information about.

Process Query Button.Click

Checks if the query message queue exists and creates it if necessary. A MessageQueue object is created to access the queue. An attempt is made to receive a message from the queue, waiting one second before giving up. If a message is received, the CustomerID is extracted from the message and the message queue is closed. A DataSet is created and a DataAdapter is used to return the record for the requested CustomerID into a Customer DataTable in the DataSet. A result queue is created if necessary and a message labeled with the CustomerID and containing the DataSet with the asynchronous query results is sent to the queue.

Process Result Button.Click

Checks if the result message queue exists and creates it if necessary. A MessageQueue object is created ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required