분석 데이터 원본에 대한 명령 실행

분석 데이터 원본에 대한 연결을 설정한 후 AdomdCommand 개체를 사용하여 해당 데이터 원본에 대한 명령을 실행하고 결과를 반환할 수 있습니다. 이러한 명령은 MDX(Multidimensional Expressions), DMX(Data Mining Extensions) 또는 제한된 SQL 구문을 사용하여 데이터를 검색할 수 있습니다. 또한 ASSL(Analysis Services Scripting Language) 명령을 사용하여 기본 데이터베이스를 수정할 수도 있습니다.

명령 만들기

명령을 실행하려면 먼저 명령을 만들어야 합니다. 다음 두 가지 방법 중 하나를 사용하여 명령을 만들 수 있습니다.

실행할 명령 텍스트는 CommandText 속성을 사용하여 쿼리하고 수정할 수 있습니다. 개발자가 만드는 명령은 실행 후 데이터를 반환하지 않아도 됩니다.

명령 실행

AdomdCommand 개체를 만든 후 해당 명령에서는 여러 Execute 메서드를 사용하여 다양한 동작을 수행할 수 있습니다. 다음 표에서는 이 중 몇 가지 동작을 보여 줍니다.

용도

사용할 메서드

결과를 데이터 스트림으로 반환

AdomdDataReader 개체를 반환하는 ExecuteReader

CellSet 개체 반환

ExecuteCellSet

행을 반환하지 않는 명령 실행

ExecuteNonQuery

XMLA(XML for Analysis) 호환 형식의 데이터가 들어 있는 XMLReader 개체 반환

ExecuteXmlReader

명령 실행 예

이 예에서는 AdomdCommand를 사용하여 데이터를 반환하지 않고 로컬 서버에서 Adventure Works DW 큐브를 처리할 XMLA 명령을 실행합니다.

        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=\"https://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();
        }