Praca z bazami danych
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.
Each Analysis server contains an MDStores collection of database objects (that is, objects of ClassType clsDatabase).Bazy danych w Decision Support Objects (DSO) zawiera wymiary i ich poziomy podrzędne źródeł danych, role i polecenia.Each database object also contains an MDStores collection of cube objects (that is, objects of ClassType clsCube.)
Następujące przykłady omówiono metody stosowane do listy, dodawanie i usuwanie baz danych na serwer analiz.
Lista baz danych
Poniższy przykład kodu łączy się z określonym serwerem DSO i iterację wszystkich baz danych na serwerze, używając MDStores kolekcja obiektu serwera analizy.
Podczas wykonywania następujący przykład kodu Drukuje nazwę i opis każdej bazy danych dla określonego serwera analizy:
Private Sub ListDatabases()
Dim dsoServer As New DSO.Server
Dim dsoDB As DSO.MDStore
' Connect to the server.
dsoServer.Connect "LocalHost"
' For each MDStore database object on the server,
' print its name.
For Each dsoDB In dsoServer.MDStores
Debug.Print "Database: " & dsoDB.Name & _
" - " & dsoDB.Description
Next
End Sub
Utwórz nową bazę danych
To create an MDStore object of ClassType clsDatabase on the server, the AddNew method of the Server.MDStores database object collection is used in the following code example.
Poniższy przykład kodu tworzy nową bazę danych, TestDB, na lokalnym serwerze Analysis:
Private Sub CreateDatabase()
Dim dsoServer As New DSO.Server
Dim dsoDB As DSO.MDStore
Dim strDBName As String
Dim strDBDesc As String
' Create a connection to the Analysis server.
dsoServer.Connect "LocalHost"
' Initialize the string variables for the
' new database name and description.
strDBName = "TestDB"
strDBDesc = "Test Database"
' Is there already a database by this name?
If dsoServer.MDStores.Find(strDBName) Then
MsgBox strDBName & " already exists."
Exit Sub
End If
' Add new database to server object collection.
' Using the AddNew method from MDStores.
Set dsoDB = dsoServer.MDStores.AddNew(strDBName)
'Assign the description to the MDStore's
'Description property, and then call the Update method.
dsoDB.Description = strDBDesc
dsoDB.Update
'Inform the user that the database was added to the server.
MsgBox (strDBName & " added to server " & dsoServer.Name)
End Sub
Usuwanie bazy danych
Aby usunąć bazę danych, użyj Remove metoda Server.MDStores kolekcja, jak pokazano w przykładzie kodu.
Następujący kod usuwa przykład TestDB bazy danych z lokalnego serwera analizy:
Private Sub RemoveDatabase()
Dim dsoServer As New DSO.Server
Dim dsoDB As DSO.MDStore
Dim strDBName As String
Dim blnResult As Boolean
' Create a connection to the Analysis server.
dsoServer.Connect "LocalHost"
' Set the database name variable to TestDB.
strDBName = "TestDB"
' Check to make sure that the TestDB database is on
' the Analysis server.
If dsoServer.MDStores.Find(strDBName) Then
' The database was on the server.
' Delete the TestDB database.
dsoServer.MDStores.Remove strDBName
' Inform the user.
MsgBox strDBName & " removed from server " & dsoServer.Name
Else
' The database was not on the server.
' Inform the user.
MsgBox strDBName & " not found on server " & dsoServer.Name
End If
End Sub
Ostrzeżenie
TestDB Bazy danych jest określone w innych przykładach.Umożliwia ponowne utworzenie bazy danych, inne przykłady przykładowy kod, pod warunkiem że wcześniej w tym temacie.