Creare e distribuire un database vuoto (AMO-TOM)
Si applica a:
SQL Server 2016 e versioni successive Analysis Services
Azure Analysis Services
Power BI Premium
Uno scenario di programmazione comune per AMO-TOM consiste nel generare database e modelli in tempo reale. Questo articolo illustra i passaggi per la creazione di un database.
Per le soluzioni tabulari, esiste una corrispondenza uno-a-uno tra un database e un modello, con un modello per ogni database. In genere è possibile specificare uno o l'altro e il motore dedurrà l'oggetto mancante.
La creazione e la distribuzione di un nuovo database sono attività in tre parti:
Creare un'istanza di un oggetto Database e impostarne le proprietà, incluso un nome.
Aggiungere l'oggetto Database a una raccolta Server.Databases.
Chiamare il metodo Update sull'oggetto Database per salvarlo nel server.
Esempio di codice: creare un database vuoto
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();
}
}
}
Passaggi successivi
Dopo aver creato un database, è possibile aggiungere oggetti Model:
Aggiungere un'origine dati a un modello tabulare
Creare tabelle, partizioni e colonne in un modello tabulare