Aracılığıyla paylaş


ado md adomd için geçiş yapma.NET

««««adomd.Ağ Kitaplığı, çok boyutlu ActiveX Veri Nesneleri (ado md) Kütüphane, bileşen nesne modeli (com) tabanlı istemci uygulamalarında çok boyutlu veri erişim için kullanılan ActiveX Data Objects (ado) Kütüphanesi uzantısı benzerdir. ado md kolay erişim sağlar çok boyutlu veri c++ gibi yönetimsiz dillerden ve MicrosoftVisual Basic. ADOMD.net analitik kolay erişim sağlar (her ikisi de çok boyutlu ve veri madenciliği) verileri yönetilen diller gibi MicrosoftC# ve MicrosoftVisual Basic.net. Ayrıca adomd.net bir Gelişmiş Meta nesne modeli sağlar.

Varolan istemci uygulamaları için adomd ado md geçirme.net kolaydır, ancak geçiş ile ilgili bazı önemli farklar vardır:

  • İstemci uygulamaları bağlantı ve veri erişimi sağlamak için

    ADO MD

    ADOMD.NET

    ADODB.dll dosyasını ve Adomd.dll başvurular gerektirir.

    Microsoft.AnalysisServices.AdomdClient.dll için tek bir başvuru gerektirir.

    AdomdConnectionSınıfı sağlar Ayrıca meta verilerine erişmek için bağlantı desteği.

  • Çok boyutlu nesneler için meta veri almak için

    ADO MD

    ADOMD.NET

    Kullanım Catalogsınıf

    Kullanım Cubesözelliği AdomdConnection.

  • Sorguları çalıştırmak ve hücre kümesi nesneleri döndürmek için

    ADO MD

    ADOMD.NET

    Kullanım CellSetsınıf

    Kullanım AdomdCommandsınıf

  • Bir hücre kümesi görüntülemek için kullanılan meta verilere erişmek için

    ADO MD

    ADOMD.NET

    Kullanım Positionsınıf

    Kullanım Setve Tuplenesnelerin.

    [!NOT]

    PositionSınıfı geriye doğru uyumluluk için desteklenir.

  • Incelemesi modeli meta verileri almak için

    ADO MD

    ADOMD.NET

    Sınıf mevcut.

    Veri incelemesi koleksiyonları birini kullanın:

Bu farklılıkları vurgulamak için eşdeğer bir adomd varolan ado md uygulama aşağıdaki geçiş örnek karşılaştırır.net bir uygulama.

Bir geçiş örneğe bakarak

Varolan ado md hem eşdeğer adomd.Bu bölümde gösterilen net kod örnekleri aynı eylemler kümesini gerçekleştirir: bağlantı kurma, çok boyutlu ifadeleri (mdx) deyimi çalıştıran ve meta verileri ve veri alınıyor. Ancak, bu iki kod kümesini aynı nesneleri bu görevler için kullanmayın.

Varolan ado md kodu

Aşağıdaki kod örneği, ado md 2.8 paketinden çizilmiş yazıldığı MicrosoftVisual Basic ® 6.0 ve kullandığı ado md nasıl bağlanmak ve sorgu göstermek için bir Microsoft  SQL Serververi kaynağını. Bu ado md örnek aşağıdaki nesneleri kullanır:

  • Gelen bir bağlantı oluşturur bir Catalognesnesini.

  • Çok boyutlu ifadeleri (mdx) deyimi kullanarak çalışan Cellsetnesnesini.

  • Meta verileri ve veri alır Positiondan alınan nesnesinin Cellsetnesnesini.

Private Sub cmdCellSettoDebugWindow_Click()
Dim cat As New ADOMD.Catalog
Dim cst As New ADOMD.Cellset
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim strServer As String
Dim strSource As String
Dim strColumnHeader As String
Dim strRowText As String

On Error GoTo Error_cmdCellSettoDebugWindow_Click
Screen.MousePointer = vbHourglass
'*-----------------------------------------------------------------------
'* Set server to local host.
'*-----------------------------------------------------------------------
    strServer = "LOCALHOST"

'*-----------------------------------------------------------------------
'* Set MDX query string source.
'*-----------------------------------------------------------------------
    strSource = strSource & "SELECT "
    strSource = strSource & "{[Measures].members} ON COLUMNS,"
    strSource = strSource & _
        "NON EMPTY [Store].[Store City].members ON ROWS"
    strSource = strSource & " FROM Sales"

'*-----------------------------------------------------------------------
'* Set active connection.
'*-----------------------------------------------------------------------
        cat.ActiveConnection = "Data Source=" & strServer & _
            ";Provider=msolap;"

'*-----------------------------------------------------------------------
'* Set cellset source to MDX query string.
'*-----------------------------------------------------------------------
        cst.Source = strSource

'*-----------------------------------------------------------------------
'* Set cellset active connection to current connection
'*-----------------------------------------------------------------------
    Set cst.ActiveConnection = cat.ActiveConnection

'*-----------------------------------------------------------------------
'* Open cellset.
'*-----------------------------------------------------------------------
    cst.Open

'*-----------------------------------------------------------------------
'* Allow space for row header text.
'*-----------------------------------------------------------------------
strColumnHeader = vbTab & vbTab & vbTab & vbTab & vbTab & vbTab

'*-----------------------------------------------------------------------
'* Loop through column headers.
'*-----------------------------------------------------------------------
       For i = 0 To cst.Axes(0).Positions.Count - 1
            strColumnHeader = strColumnHeader & _
                cst.Axes(0).Positions(i).Members(0).Caption & vbTab & _
                    vbTab & vbTab & vbTab
       Next
       Debug.Print vbTab & strColumnHeader & vbCrLf

'*-----------------------------------------------------------------------
'* Loop through row headers and provide data for each row.
'*-----------------------------------------------------------------------
        strRowText = ""
        For j = 0 To cst.Axes(1).Positions.Count - 1
            strRowText = strRowText & _
                cst.Axes(1).Positions(j).Members(0).Caption & vbTab & _
                    vbTab & vbTab & vbTab
            For k = 0 To cst.Axes(0).Positions.Count - 1
                strRowText = strRowText & cst(k, j).FormattedValue & _
                    vbTab & vbTab & vbTab & vbTab
            Next
            Debug.Print strRowText & vbCrLf
            strRowText = ""
        Next

    Screen.MousePointer = vbDefault
Exit Sub

Error_cmdCellSettoDebugWindow_Click:
   Beep
   Screen.MousePointer = vbDefault
   MsgBox "The following error has occurred:" & vbCrLf & _
      Err.Description, vbCritical, " Error!"
   Exit Sub
End Sub

Private Sub cmdCellSettoDebugWindow_Click()
Dim cat As New ADOMD.Catalog
Dim cst As New ADOMD.Cellset
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim strServer As String
Dim strSource As String
Dim strColumnHeader As String
Dim strRowText As String

On Error GoTo Error_cmdCellSettoDebugWindow_Click
Screen.MousePointer = vbHourglass
'*-----------------------------------------------------------------------
'* Set server to local host.
'*-----------------------------------------------------------------------
    strServer = "LOCALHOST"

'*-----------------------------------------------------------------------
'* Set MDX query string source.
'*-----------------------------------------------------------------------
    strSource = strSource & "SELECT "
    strSource = strSource & "{[Measures].members} ON COLUMNS,"
    strSource = strSource & _
        "NON EMPTY [Store].[Store City].members ON ROWS"
    strSource = strSource & " FROM Sales"

'*-----------------------------------------------------------------------
'* Set active connection.
'*-----------------------------------------------------------------------
        cat.ActiveConnection = "Data Source=" & strServer & _
            ";Provider=msolap;"

'*-----------------------------------------------------------------------
'* Set cellset source to MDX query string.
'*-----------------------------------------------------------------------
        cst.Source = strSource

'*-----------------------------------------------------------------------
'* Set cellset active connection to current connection
'*-----------------------------------------------------------------------
    Set cst.ActiveConnection = cat.ActiveConnection

'*-----------------------------------------------------------------------
'* Open cellset.
'*-----------------------------------------------------------------------
    cst.Open

'*-----------------------------------------------------------------------
'* Allow space for row header text.
'*-----------------------------------------------------------------------
strColumnHeader = vbTab & vbTab & vbTab & vbTab & vbTab & vbTab

'*-----------------------------------------------------------------------
'* Loop through column headers.
'*-----------------------------------------------------------------------
       For i = 0 To cst.Axes(0).Positions.Count - 1
            strColumnHeader = strColumnHeader & _
                cst.Axes(0).Positions(i).Members(0).Caption & vbTab & _
                    vbTab & vbTab & vbTab
       Next
       Debug.Print vbTab & strColumnHeader & vbCrLf

'*-----------------------------------------------------------------------
'* Loop through row headers and provide data for each row.
'*-----------------------------------------------------------------------
        strRowText = ""
        For j = 0 To cst.Axes(1).Positions.Count - 1
            strRowText = strRowText & _
                cst.Axes(1).Positions(j).Members(0).Caption & vbTab & _
                    vbTab & vbTab & vbTab
            For k = 0 To cst.Axes(0).Positions.Count - 1
                strRowText = strRowText & cst(k, j).FormattedValue & _
                    vbTab & vbTab & vbTab & vbTab
            Next
            Debug.Print strRowText & vbCrLf
            strRowText = ""
        Next

    Screen.MousePointer = vbDefault
Exit Sub

Error_cmdCellSettoDebugWindow_Click:
   Beep
   Screen.MousePointer = vbDefault
   MsgBox "The following error has occurred:" & vbCrLf & _
      Err.Description, vbCritical, " Error!"
   Exit Sub
End Sub

Eşdeğer adomd.net kodu

Aşağıdaki örnek, Visual Basic'te yazılmış.net ve adomd kullanıyor.net, önceki Visual Basic 6.0 örnek aynı eylemleri gerçekleştirmek gösterilmiştir. Aşağıdaki örnek ve daha önce gösterilen ado md örnek arasındaki en önemli fark, eylemleri gerçekleştirmek için kullanılan nesneleri olduğunu. ««««adomd.net örnek aşağıdaki nesneleri kullanır:

  • İle bir bağlantı oluşturur bir AdomdConnectionnesnesini.

  • mdx deyimi kullanarak başka bir AdomdCommandnesnesini.

  • Meta verileri ve veri alır Setdan alınan nesnesinin Cellsetnesnesini.

Private Sub DisplayCellSetInOutputWindow()
    Dim conn As AdomdConnection
    Dim cmd As AdomdCommand
    Dim cst As CellSet
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim strServer As String = "LOCALHOST"
    Dim strSource As String = "SELECT [Measures].members ON COLUMNS, " & _
        "NON EMPTY [Store].[Store City].members ON ROWS FROM SALES"
    Dim strOutput As New System.IO.StringWriter

    '*-----------------------------------------------------------------------
    '* Open connection.
    '*-----------------------------------------------------------------------
    Try
        ' Create a new AdomdConnection object, providing the connection
        ' string.
        conn = New AdomdConnection("Data Source=" & strServer & _
        ";Provider=msolap;")
        ' Open the connection.
        conn.Open()
    Catch ex As Exception
        Throw New ApplicationException( _
            "An error occurred while connecting.")
    End Try

    Try
    '*-----------------------------------------------------------------------
    '* Open cellset.
    '*-----------------------------------------------------------------------
        ' Create a new AdomdCommand object, providing the MDX query string.
        cmd = New AdomdCommand(strSource, conn)
        ' Run the command and return a CellSet object.
        cst = cmd.ExecuteCellSet()

    '*-----------------------------------------------------------------------
    '* Concatenate output.
    '*-----------------------------------------------------------------------

    ' Include spacing to account for row headers.
    strOutput.Write(vbTab, 6)

    ' Iterate through the first axis of the CellSet object and
    ' retrieve column headers.
    For i = 0 To cst.Axes(0).Set.Tuples.Count - 1
        strOutput.Write(cst.Axes(0).Set.Tuples(i).Members(0).Caption)
        strOutput.Write(vbTab, 4)
    Next
    strOutput.WriteLine()

    ' Iterate through the second axis of the CellSet object and
    ' retrieve row headers and cell data.
    For j = 0 To cst.Axes(1).Set.Tuples.Count - 1
        ' Append the row header.
        strOutput.Write(cst.Axes(1).Set.Tuples(j).Members(0).Caption)
        strOutput.Write(vbTab, 4)

        ' Append the cell data for that row.
        For k = 0 To cst.Axes(0).Set.Tuples.Count - 1
            strOutput.Write(cst.Cells(k, j).FormattedValue)
            strOutput.Write(vbTab, 4)
        Next
        strOutput.WriteLine()
    Next

    ' Display the output.
    Debug.WriteLine(strOutput.ToString)

    '*-----------------------------------------------------------------------
    '* Release resources.
    '*-----------------------------------------------------------------------
        conn.Close()
    Catch ex As Exception
        ' Ignore or handle errors.
    Finally
        cst = Nothing
        cmd = Nothing
        conn = Nothing
    End Try
End Sub

Private Sub DisplayCellSetInOutputWindow()
    Dim conn As AdomdConnection
    Dim cmd As AdomdCommand
    Dim cst As CellSet
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim strServer As String = "LOCALHOST"
    Dim strSource As String = "SELECT [Measures].members ON COLUMNS, " & _
        "NON EMPTY [Store].[Store City].members ON ROWS FROM SALES"
    Dim strOutput As New System.IO.StringWriter

    '*-----------------------------------------------------------------------
    '* Open connection.
    '*-----------------------------------------------------------------------
    Try
        ' Create a new AdomdConnection object, providing the connection
        ' string.
        conn = New AdomdConnection("Data Source=" & strServer & _
        ";Provider=msolap;")
        ' Open the connection.
        conn.Open()
    Catch ex As Exception
        Throw New ApplicationException( _
            "An error occurred while connecting.")
    End Try

    Try
    '*-----------------------------------------------------------------------
    '* Open cellset.
    '*-----------------------------------------------------------------------
        ' Create a new AdomdCommand object, providing the MDX query string.
        cmd = New AdomdCommand(strSource, conn)
        ' Run the command and return a CellSet object.
        cst = cmd.ExecuteCellSet()

    '*-----------------------------------------------------------------------
    '* Concatenate output.
    '*-----------------------------------------------------------------------

    ' Include spacing to account for row headers.
    strOutput.Write(vbTab, 6)

    ' Iterate through the first axis of the CellSet object and
    ' retrieve column headers.
    For i = 0 To cst.Axes(0).Set.Tuples.Count - 1
        strOutput.Write(cst.Axes(0).Set.Tuples(i).Members(0).Caption)
        strOutput.Write(vbTab, 4)
    Next
    strOutput.WriteLine()

    ' Iterate through the second axis of the CellSet object and
    ' retrieve row headers and cell data.
    For j = 0 To cst.Axes(1).Set.Tuples.Count - 1
        ' Append the row header.
        strOutput.Write(cst.Axes(1).Set.Tuples(j).Members(0).Caption)
        strOutput.Write(vbTab, 4)

        ' Append the cell data for that row.
        For k = 0 To cst.Axes(0).Set.Tuples.Count - 1
            strOutput.Write(cst.Cells(k, j).FormattedValue)
            strOutput.Write(vbTab, 4)
        Next
        strOutput.WriteLine()
    Next

    ' Display the output.
    Debug.WriteLine(strOutput.ToString)

    '*-----------------------------------------------------------------------
    '* Release resources.
    '*-----------------------------------------------------------------------
        conn.Close()
    Catch ex As Exception
        ' Ignore or handle errors.
    Finally
        cst = Nothing
        cmd = Nothing
        conn = Nothing
    End Try
End Sub

Ayrıca bkz.

Kavramlar

ADOMD.AĞ istemcisi kavramlar ve nesne modeli