Databases Reference
In-Depth Information
When the user clicks the Cancel button, the sample application calls the
server.CancelCommand
method, which issues the
Cancel
DDL command. You can read
about the
Cancel
command in Chapter 26. The
Cancel
command does not immediately
cancel the running command; on the server, the
Cancel
command turns on a flag that
signals to the session that it should stop all operations and returns to the client applica-
tion. All server operations periodically check this flag; if it is turned on, the server starts
the canceling process. The response generated by the server differs depending on the
processing stage being executed at the moment you clicked the Cancel button. Therefore,
the sample application might show different message boxes every time you click the
Cancel button. If you issue the
Cancel
command more than one time, Analysis Services
might generate an error telling you that the command already been canceled; AMO propa-
gates this error to the caller as an exception. This sample application captures all the
exceptions thrown by
server.CancelCommand
.
AMO Object Loading
After a connection to the server is established, the client application can use AMO inter-
faces to enumerate all the metadata objects that exist on the server. AMO retrieves meta-
data information from the server by sending
DISCOVER_XML_METADATA
requests. However, it
would not be very efficient to download the metadata information about all the objects
on the server in one request.
AMO has an intelligent mechanism for downloading metadata from the server. The idea is
that only the objects that are needed or requested by the application are downloaded to
the client. For example, after establishing the connection to the server, AMO populates
the
Databases
collection and other collections of major objects that are children of the
server object (such as
Traces
,
Assemblies
,
Roles
, and
ServerProperties
), by sending a
DISCOVER_XML_METADATA
request with an
ObjectExpansion
restriction set to
ExpandObject
.
The server sends back the properties of the current object (
Server
) and the
Name
,
ID
, and
several other properties (such as
CreatedTimestamp
,
LastSchemaUpdate
,
LastProcessed
,
State
, and
LastUpdated
) of the major objects it contains.
When the client code tries to access a property of one of those contained objects, AMO
sends a request to the server for more information. If the requested property has already
been retrieved, AMO returns the property value that is cached on the client. Listing 34.9
shows at what time which object will be downloaded from the server.
LISTING 34.9
Loading AMO Objects from the Server
using (Server srv = new Server())
{
string connectionString = “Datasource=localhost;”;
//The following code will connect to the server and send a
//DISCOVER_XML_METADATA request, then AMO will populate all the properties
//of the server object and create collections of major contained objects.
srv.Connect(connectionString);
Search WWH ::
Custom Search