AdomdConnection Class

Represents a connection to a multidimensional data source.

Namespace:  Microsoft.AnalysisServices.AdomdClient
Assembly:  Microsoft.AnalysisServices.AdomdClient (in Microsoft.AnalysisServices.AdomdClient.dll)


Public NotInheritable Class AdomdConnection _
    Inherits Component _
    Implements IDbConnection, IDisposable, ICloneable
Dim instance As AdomdConnection
public sealed class AdomdConnection : Component, 
    IDbConnection, IDisposable, ICloneable
public ref class AdomdConnection sealed : public Component, 
    IDbConnection, IDisposable, ICloneable
type AdomdConnection =  
        inherit Component
        interface IDbConnection
        interface IDisposable
        interface ICloneable
public final class AdomdConnection extends Component implements IDbConnection, IDisposable, ICloneable


The AdomdConnection represents a connection with an analytical data source (for example, a connection to an instance of Microsoft SQL Server 2005 Analysis Services (SSAS)). Each connection is associated with an XML for Analysis session. If an AdomdConnection goes out of scope, the connection is not closed. To close the connection, you must explicitly call the Close or Dispose method of the AdomdConnection. If the Close or Dispose method is not called, the session associated with the AdomdConnection remains active and can be reused by another AdomdConnection. For more information about managing sessions, see Working with Connections and Sessions in ADOMD.NET and SessionID.


The following subroutine uses the given arguments to build a connection string that the subroutine uses to try to connect to a specified instance of Analysis Services and return an AdomdConnection:

Public Function Connect(Optional ByVal ServerID As String = "localhost", _
    Optional ByVal DatabaseID As String = "", _
    Optional ByVal UserID As String = "", _
    Optional ByVal Password As String = "") As AdomdConnection

    Dim strConnectionString As String
    Dim objConnection As AdomdConnection

        ' First, build the connection string.
        ' The ConnectionString property consists of 
        ' key/value pairs seperated by semicolons.
        ' - The format, as a regular expression, should be:
        ' (<Key>=<Value>)*([[;]/*(<Key>=<Value>)])

        ' The connection string can take "Datasource", "Data Source", 
        ' or "Location" for this parameter.
        If ServerID <> "" Then
            strConnectionString &= "Data Source=" & ServerID & ";"
        End If

        ' The connection string can take "Catalog" or "Initial Catalog" 
        ' for this parameter.
        If DatabaseID <> "" Then
            strConnectionString &= "Initial Catalog=" & DatabaseID & ";"
        End If

        ' The connection string can take "UID", "User ID", 
        ' "Authenticated User", or "UserName" for this parameter.
        If UserID <> "" Then
            strConnectionString &= "User ID=" & UserID & ";"
        End If

        ' The connection string can take "PWD" or "Password" 
        ' for this parameter.
        If Password <> "" Then
            strConnectionString &= "Password=" & Password & ";"
        End If

        ' Get a reference to an AdomdConnection object.
        objConnection = New AdomdConnection()

        ' Assign the connection string and try to 
        ' open a connection.
        objConnection.ConnectionString = strConnectionString

        Catch ex As AdomdConnectionException
            ' The connection could not be opened or was disconnected.
            ' This error can occur at any time, if the provider is 
            ' disconnected from the server.
        Catch ex As AdomdErrorResponseException
            ' A response is received from a provider that indicates an error.
        Catch ex As AdomdUnknownResponseException
            ' A response has been returned from the provider that 
            ' was not understood.
        Catch ex As AdomdCacheExpiredException
            ' A cached version of an ADOMD.NET object is no longer valid.
            ' This error is typically raised when reviewing metadata.
        Catch ex As AdomdException
            ' Any other error raised by ADOMD.NET.
        Catch ex As Exception
            ' Any other error that occurs.
        Debug.Write("The connection ")
        If objConnection.State = ConnectionState.Open Then
            Debug.WriteLine("is connected!")
            Debug.WriteLine("failed to connect!")
        End If
    End Try
    ' Return the AdomdConnection object.
    Return objConnection
End Function

Inheritance Hierarchy


Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.