Databases Reference
In-Depth Information
command.CommandText = “SELECT Measures.Members ON COLUMNS FROM [Warehouse and
Sales]”;
//Execute command...
//...
// Close the connection.
con.Close();
In most cases, the request sent to the server is small enough. For example, even the
longest MDX request will hardly exceed two or three pages of text. However, some Data
Definition Language (DDL) requests that can be sent to the server using ADOMD.NET are
quite large and can take much more memory on the client computer. It is not optimal to
construct such a request as a string and send it through the CommandText property.
For large DDL requests, ADOMD.NET provides the CommandStream property, which accepts
the object that implements the IStream interface. Because only well-formed XML can be
sent to the server, ADOMD.NET has to perform some operations to determine whether the
stream contains XML or just plain text. To do this, ADOMD.NET uses a simple algorithm
that reads the first symbol of the request. If the first character is < , ADOMD.NET assumes
that stream contains an XML element. But if the first character is some other symbol,
ADOMD.NET wraps the request with the <Statement> element before it sends the request
to the server.
ADOMD.NET allows only one of two properties to be set: either CommandText or
CommandStream . Listing 33.13 uses CommandStream .
LISTING 33.13
Using CommandStream
//Open a connection to the server.
AdomdConnection con = new AdomdConnection();
con.ConnectionString = “Datasource=localhost;”;
con.Open();
//Open a stream for reading a file that contains the XML for creating a cube
System.IO.StreamReader sr = new System.IO.StreamReader
(“..\\..\\Foodmart2008Metadata.xml””, true);
AdomdCommand command = con.CreateCommand();
command.CommandStream = sr.BaseStream;
// Execute the command
command.ExecuteNonQuery();
// Close the stream
sr.Close();
 
Search WWH ::




Custom Search