分析データ ソースに対するコマンドの実行

分析データ ソースに接続したら、 AdomdCommand オブジェクトを使用してコマンドを実行し、結果を返します。 データを取得するには、多次元式 (MDX)、データ マイニング拡張機能 (DMX)、または制限付き SQL 構文を使用します。 Analysis Services スクリプト言語 (ASSL) コマンドを使用して、基になるデータベースを変更します。

コマンドの作成

コマンドを実行する前に作成します。 次の 2 つの方法のいずれかを使用します。

コマンド テキストを取得または設定するには、 CommandText プロパティを使用します。 コマンドの実行時にデータを返す必要はありません。

コマンドの実行

AdomdCommand オブジェクトを作成した後、そのExecuteメソッドのいずれかを使用してコマンドを実行するか、結果を返します。 次の表では、これらのメソッドの一部について説明します。

移行先 この方法を使用する
データのストリームとして結果を返す ExecuteReader AdomdDataReader オブジェクトを返すために
CellSet オブジェクトを返す ExecuteCellSet
行を返さないコマンドを実行する ExecuteNonQuery
XML for Analysis (XMLA) 準拠形式のデータを含む XMLReader オブジェクトを返します。 ExecuteXmlReader

コマンドの実行例

この例では、 AdomdCommand オブジェクトを使用して XMLA コマンドを実行します。 このコマンドは、データを返さずにローカル サーバー上の Adventure Works DW キューブを処理します。

        void ExecuteXMLAProcessCommand()
        {
            //Open a connection to the local server
            AdomdConnection conn = new AdomdConnection("Data Source=localhost");
            conn.Open();

            //Create a command, and assign it an XMLA command to process the cube.
            AdomdCommand cmd = conn.CreateCommand();
            cmd.CommandText = "<Process xmlns=\"http://schemas.microsoft.com/analysisservices/2003/engine\">\r\n" +
  @"<Object>
    <DatabaseID>Adventure Works DW Standard Edition</DatabaseID>
    <CubeID>Adventure Works DW</CubeID>
  </Object>
  <Type>ProcessFull</Type>
  <WriteBackTableCreation>UseExisting</WriteBackTableCreation>
</Process>";

            //Execute the command
            int result = cmd.ExecuteNonQuery();

            //Close the connection
            conn.Close();
        }