空のデータベースを作成してデプロイする (AMO-TOM)

適用対象:SQL Server 2016 以降 Analysis Services Azure Analysis Services Power BI Premium

AMO の一般的なプログラミングシナリオでは、データベースとモデルを即座に生成します。 この記事では、データベースを作成する手順について説明します。

テーブルソリューションでは、データベースとモデルの間に1対1の対応があり、データベースごとに1つのモデルがあります。 通常はどちらか一方を指定することができ、不足しているオブジェクトがエンジンによって推論されます。

新しいデータベースの作成と展開は、3つの部分から構成されるタスクです。

  • データベースオブジェクトをインスタンス化し、そのプロパティ (名前を含む) を設定します。

  • Databaseオブジェクトをサーバーの Databasesコレクションに追加します。

  • データベースオブジェクトでUpdateメソッドを呼び出して、サーバーに保存します。

コード例: 空のデータベースの作成

using System; 
using Microsoft.AnalysisServices; 
using Microsoft.AnalysisServices.Tabular; 
 
namespace TOMSamples 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 
            // 
            // Connect to the local default instance of Analysis Services 
            // 
            string ConnectionString = "DataSource=localhost"; 
 
            // 
            // The using syntax ensures the correct use of the 
            // Microsoft.AnalysisServices.Tabular.Server object. 
            // 
            using (Server server = new Server()) 
            { 
                server.Connect(ConnectionString); 
 
                // 
                // Generate a new database name and use GetNewName 
                // to ensure the database name is unique. 
                // 
                string newDatabaseName = 
                    server.Databases.GetNewName("New Empty Database"); 
 
                // 
                // Instantiate a new  
                // Microsoft.AnalysisServices.Tabular.Database object. 
                // 
                var blankDatabase = new Database() 
                { 
                    Name = newDatabaseName, 
                    ID = newDatabaseName, 
                    CompatibilityLevel = 1200, 
                    StorageEngineUsed = StorageEngineUsed.TabularMetadata, 
                }; 
                // 
                // Add the new database object to the server's  
                // Databases connection and submit the changes 
                // with full expansion to the server. 
                // 
                server.Databases.Add(blankDatabase); 
                blankDatabase.Update(UpdateOptions.ExpandFull); 

                Console.Write("Database "); 
                Console.ForegroundColor = ConsoleColor.Yellow; 
                Console.Write(blankDatabase.Name); 
                Console.ResetColor(); 
                Console.WriteLine(" created successfully."); 
                Console.WriteLine(); 
            } 
            Console.WriteLine("Press Enter to close this console window."); 
            Console.ReadLine(); 
        } 
    } 
} 

次の手順

データベースを作成したら、モデルオブジェクトを追加できます。

テーブルモデルへのデータソースの追加
テーブルモデルでのテーブル、パーティション、および列の作成