Eventi
31 mar, 23 - 2 apr, 23
Il più grande evento di apprendimento di Fabric, Power BI e SQL. 31 marzo - 2 aprile. Usare il codice FABINSIDER per salvare $400.
Iscriviti oggi stessoQuesto browser non è più supportato.
Esegui l'aggiornamento a Microsoft Edge per sfruttare i vantaggi di funzionalità più recenti, aggiornamenti della sicurezza e supporto tecnico.
Si applica a: SQL Server 2016 e versioni successive di Analysis Services
Azure Analysis Services
Fabric/Power BI Premium
La classe DataSource nello spazio dei nomi Microsoft.AnalysisServices.Tabular è un'astrazione dell'origine dati di un modello tabulare che specifica il tipo e la posizione dei dati importati durante un'operazione di aggiornamento dati.
È possibile aggiungere un'origine dati al modello tabulare creando un'istanza di un oggetto di una classe derivata da DataSource e quindi aggiungerla all'insieme DataSources dell'oggetto Model. Per eseguire il commit delle modifiche al server, chiamare Model.SaveChanges() o Database.Update(UpdateOptions.ExpandFull).
I modelli tabulari supportano l'importazione dei dati solo da origini dati relazionali, in cui il provider di dati espone i dati sotto forma di tabelle e colonne. Di conseguenza, il modello a oggetti tabulari usa la classe ProviderDataSource (derivata da DataSource) per esporre questa funzionalità.
Questo esempio illustra come creare un'istanza di ProviderDataSource e aggiungerla a un modello di dati.
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("Database with a Data Source Definition");
//
// Instantiate a new
// Microsoft.AnalysisServices.Tabular.Database object.
//
var dbWithDataSource = new Database()
{
Name = newDatabaseName,
ID = newDatabaseName,
CompatibilityLevel = 1200,
StorageEngineUsed = StorageEngineUsed.TabularMetadata,
};
//
// Add a Microsoft.AnalysisServices.Tabular.Model object to the
// database, which acts as a root for all other Tabular metadata objects.
//
dbWithDataSource.Model = new Model()
{
Name = "Tabular Data Model",
Description = "A Tabular data model at the 1200 compatibility level."
};
//
// Add a Microsoft.AnalysisServices.Tabular.ProviderDataSource object
// to the data Model object created in the previous step. The connection
// string of the data source object in this example
// points to an instance of the AdventureWorks2014 SQL Server database.
//
dbWithDataSource.Model.DataSources.Add(new ProviderDataSource()
{
Name = "SQL Server Data Source Example",
Description = "A data source definition that uses explicit Windows credentials for authentication against SQL Server.",
ConnectionString = "Provider=SQLNCLI11;Data Source=localhost;Initial Catalog=AdventureWorks2014;Integrated Security=SSPI;Persist Security Info=false",
ImpersonationMode = Microsoft.AnalysisServices.Tabular.ImpersonationMode.ImpersonateAccount,
Account = @".\Administrator",
Password = "P@ssw0rd",
});
//
// Add the new database object to the server's
// Databases connection and submit the changes
// with full expansion to the server.
//
server.Databases.Add(dbWithDataSource);
dbWithDataSource.Update(UpdateOptions.ExpandFull);
Console.Write("Database ");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write(dbWithDataSource.Name);
Console.ResetColor();
Console.WriteLine(" created successfully.");
Console.WriteLine("The data model includes the following data source definitions:");
Console.ForegroundColor = ConsoleColor.Yellow;
foreach (DataSource ds in dbWithDataSource.Model.DataSources)
{
Console.WriteLine("\tData source name:\t\t{0}", ds.Name);
Console.WriteLine("\tData source description:\t{0}", ds.Description);
}
Console.ResetColor();
Console.WriteLine();
}
Console.WriteLine("Press Enter to close this console window.");
Console.ReadLine();
}
}
}
All'interno di un modello è necessario configurare i data binding che eseguono il mapping delle colonne di origine nell'origine dati alle colonne di destinazione nel modello. Sarà anche necessario definire le partizioni, almeno una per tabella, che archivia i dati. Il collegamento seguente illustra come creare tabelle, partizioni e colonne
Eventi
31 mar, 23 - 2 apr, 23
Il più grande evento di apprendimento di Fabric, Power BI e SQL. 31 marzo - 2 aprile. Usare il codice FABINSIDER per salvare $400.
Iscriviti oggi stesso