共用方式為


資料庫表示法(表格式)

在表格式模式中,資料庫是表格式模型中所有物件的容器。

資料庫表示法

資料庫是構成表格式模型的所有物件所在位置。 由資料庫所包含,開發人員會尋找諸如連接、數據表、角色等物件。

AMO 中的資料庫

使用 AMO 來管理表格式模型資料庫時, Database AMO 中的物件會比對表格式模型中的資料庫邏輯物件一對一。

備註

若要取得資料庫物件的存取權,在 AMO 中,用戶必須能夠存取伺服器物件並連線到它。

ADOMD.Net 中的資料庫

使用 ADOMD 查閱及查詢表格式模型資料庫時,會透過 AdomdConnection 物件取得與特定資料庫的連線。

您可以使用下列代碼段直接連線到特定資料庫:

using ADOMD = Microsoft.AnalysisServices.AdomdClient;  
...  
   ADOMD.AdomdConnection currrentCnx = new ADOMD.AdomdConnection("Data Source=<<server\instance>>;Catalog=<<database>>");  
   currrentCnx.Open();  
...  
  

此外,透過現有的連接物件(尚未關閉),您可以將目前的資料庫變更為另一個資料庫,如下列代碼段所示:

currentCnx.ChangeDatabase("myOtherDatabase");  
  

AMO 中的資料庫

使用 AMO 來管理資料庫物件時,請從 對象開始 Server 。 然後,在資料庫集合中搜尋您的資料庫,或藉由將資料庫加入至集合來建立新的資料庫。

下列代碼段顯示連線到伺服器並建立空白資料庫的步驟,檢查資料庫不存在:

  
AMO.Server CurrentServer = new AMO.Server();  
try  
{  
    CurrentServer.Connect(currentServerName);  
}  
catch (Exception cnxException)  
{  
    MessageBox.Show(string.Format("Error while trying to connect to server: [{0}]\nError message: {1}", currentServerName, cnxException.Message), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Error);  
    return;  
}  
newDatabaseName = DatabaseName.Text;  
if (CurrentServer.Databases.Contains(newDatabaseName))  
{  
    return;  
}  
try  
{  
    AMO.Database newDatabase = CurrentServer.Databases.Add(newDatabaseName);  
  
    CurrentServer.Update();  
}  
catch (Exception createDBxc)  
{  
    MessageBox.Show(String.Format("Database [{0}] couldn't be created.\n{1}", newDatabaseName, createDBxc.Message), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Error);  
    newDatabaseAvailable = false;  
}  
  

如需如何使用 AMO 來建立及作資料庫表示法的實際瞭解,請參閱表格式 AMO 2012 範例中的原始碼:請特別簽入下列原始程序檔:Database.cs。 範例程式代碼只提供這裡所說明邏輯概念的支援,而且不應該在生產環境中使用。