Udostępnij za pośrednictwem


clsDataSource

Ostrzeżenie

  Ta funkcja zostanie usunięta z następnej wersji programu Microsoft SQL Server. Nie należy stosować tej funkcji w nowych projektach oraz jak najszybciej należy zmodyfikować aplikacje, w których obecnie jest używana ta funkcja.

An object of ClassType clsDataSource specifies an external database that will be used as a source of data for an object of ClassType clsDatabase, clsCube, or clsPartition.The object of ClassType clsDataSource providescollections, methods, and properties though its own internal interface.

Uwagi

Połączenia ze źródłami danych są inicjowane, gdy Decision Support Objects (DSO) wymaga dostępu do danych lub właściwość informacji w źródłowa baza danych.Źródła danych są połączone tylko potrzebne lub wyraźnie zażądanej przez program.Executing the IsConnected method of an object of ClassType clsDataSource causes the Analysis server to attempt to connect to the specified data source.

Obiekt ClassType clsDatabase może zawierać wiele obiektów z ClassType clsDataSource w jego DataSources kolekcja.Obiekty ClassType clsCube i clsPartition może zawierać tylko jeden obiekt z ClassType clsDataSource w ich odpowiednich DataSources kolekcja.An aggregation object (ClassType clsAggregation) does not implement the DataSources collection of the MDStore interface.

Przykłady

A.Tworzenie nowej bazy danych

Poniższy przykład ilustruje sposób połączyć serwer analiz i Utwórz nową bazę danych, dołącz źródło danych i Dodaj wymiar udostępniony i poziom.It uses the sample FoodMart 2000 database.Po budynku i uruchomiony kod przykładowy, powinny być możliwe wyświetlenie nowej bazie danych Analysis Manager.

Option Explicit
Public dsoServer As DSO.Server
Const strConnect = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=FoodMart 2000;Connect Timeout=15"

'Note: Add command control to form to enable
'      the cmdCreateDatabase_Click method

Private Sub cmdCreateDatabase_Click()
    On Error GoTo CreateDatabase_Err
    
    Dim dsoDB As DSO.MDStore
    Dim dsoDS As DSO.Datasource
    
    'Create database and add connection string
    Set dsoDB = dsoServer.MDStores.AddNew("MyDatabase")
    Set dsoDS = dsoDB.Datasources.AddNew("NewSales")
    dsoDS.ConnectionString = strConnect
    dsoDS.Update
    
    'Create dimension and set data source
    Dim dsoDim As DSO.Dimension
    Set dsoDim = dsoDB.Dimensions.AddNew("Products")
    Set dsoDim.Datasource = dsoDS
    dsoDim.FromClause = "product"
    dsoDim.JoinClause = ""
    
    'Add levels
    Dim dsoLev As DSO.Level
    Set dsoLev = dsoDim.Levels.AddNew("Product Id")
    'Point to table and column
    dsoLev.MemberKeyColumn = """product_class"".""product_family"""
   dsoLev.ColumnSize = 4            'Width of column in bytes
    dsoLev.ColumnType = adInteger   'ADODB Data Type
    
    dsoDim.Update
    
    Debug.Print "<<success>>"
    
    Exit Sub

CreateDatabase_Err:
    Debug.Print "Error creating new database"
    Debug.Print Err.Description
    Err.Clear
End Sub

Private Sub Form_Load()
    On Error GoTo FormLoad_Err
    
    'Connect to the Analysis server
    Set dsoServer = New DSO.Server
    'MyServer is the name of the Analysis server 
    dsoServer.Connect ("MyServer")
    Debug.Print ("Connected")
    Exit Sub
    
FormLoad_Err:
    Debug.Print ("Error connecting to server")
    Debug.Print Err.Description
    Err.Clear
End Sub

B.Podłączanie do dostawców źródła danych

Połączenie ciąg przykłady przewidziano również następujący dostawcy źródło danych:

Microsoft ® dostawcy OLE DB dla aparatu Jet 3.51 OLE DB:

  ConnectionString="Provider=Microsoft.Jet.OLEDB.3.51;" & _
  "Persist Security Info=False;" & _
  "Data Source=C:\Program Files\" & _
  "Microsoft Analysis Services\Samples\FoodMart 2000.mdb" 

Microsoft OLE DB Provider for Jet 4.0:

  ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;" & _
  "Persist Security Info=False;" & _
  "Data Source=C:\Program Files\" & _
  "Microsoft Analysis Services\Samples\FoodMart 2000.mdb;" & _
  "JET OLEDB:SFP=True;"

Dostawca Microsoft OLE DB dla ODBC (program Microsoft Access):

  ConnectionString="Provider=MSDASQL.1;" & _
  "Persist Security Info=False;" & _
  "Data Source=FoodMart 2000;" & _
  "Connect Timeout=15"

Microsoft SQL Server ™:

  ConnectionString = "Provider=SQLOLEDB.1;" & _
  "Persist Security Info=False;" & _
  "User ID=sa;" & _
  "Initial Catalog=FoodMart 2000;" & _
  "Data Source={SQL Server};" & _
  "Connect Timeout=15"