AdomdConnection 類別
Represents a connection to a multidimensional data source.
命名空間: 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
備註
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 使用連接和 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
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
執行緒安全性
這個類型的任何公用static (在 Visual Basic 中為 Shared) 成員都是安全執行緒。不保證任何執行個體成員都可以是安全執行緒。