次の方法で共有


AdomdConnection クラス

多次元データ ソースへの接続を表します。

名前空間:  Microsoft.AnalysisServices.AdomdClient
アセンブリ:  Microsoft.AnalysisServices.AdomdClient (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
[<SealedAttribute>]
type AdomdConnection =  
    class
        inherit Component
        interface IDbConnection
        interface IDisposable
        interface ICloneable
    end
public final class AdomdConnection extends Component implements IDbConnection, IDisposable, ICloneable

説明

AdomdConnection は、分析データ ソースとの接続 (MicrosoftSQL Server 2005 Analysis Services (SSAS) のインスタンスへの接続など) を表します。各接続は、XML for Analysis セッションと関連付けられます。AdomdConnection がスコープ外になっても、接続は閉じません。接続を閉じるには、AdomdConnection の Close メソッドまたは Dispose メソッドを明示的に呼び出す必要があります。Close メソッドも Dispose メソッドも呼び出されない場合は、AdomdConnection に関連付けられたセッションがアクティブなままとなり、別の AdomdConnection によるセッションの再利用が可能になります。セッションの管理の詳細については、「ADOMD.NET での接続およびセッションの使用」および「SessionID」を参照してください。

使用例

次のサブルーチンでは、接続文字列の作成に使用する引数を受け取り、指定された Analysis Services インスタンスに接続して、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

    Try
        ' 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
        objConnection.Open()

        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.
            Debug.WriteLine(ex)
        Catch ex As AdomdErrorResponseException
            ' A response is received from a provider that indicates an error.
            Debug.WriteLine(ex)
        Catch ex As AdomdUnknownResponseException
            ' A response has been returned from the provider that 
            ' was not understood.
            Debug.WriteLine(ex)
        Catch ex As AdomdCacheExpiredException
            ' A cached version of an ADOMD.NET object is no longer valid.
            ' This error is typically raised when reviewing metadata.
            Debug.WriteLine(ex)
        Catch ex As AdomdException
            ' Any other error raised by ADOMD.NET.
            Debug.WriteLine(ex)
        Catch ex As Exception
            ' Any other error that occurs.
            Debug.WriteLine(ex)
    Finally
        Debug.Write("The connection ")
        If objConnection.State = ConnectionState.Open Then
            Debug.WriteLine("is connected!")
        Else
            Debug.WriteLine("failed to connect!")
        End If
    End Try
    
    ' Return the AdomdConnection object.
    Return objConnection
End Function

継承階層

System. . :: . .Object
  System. . :: . .MarshalByRefObject
    System.ComponentModel. . :: . .Component
      Microsoft.AnalysisServices.AdomdClient..::..AdomdConnection

スレッド セーフ

この型の public static (Visual Basic では Shared) のメンバーはすべて、スレッド セーフです。インスタンス メンバーの場合は、スレッド セーフであるとは限りません。