Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Berlaku untuk: SQL Server 2016 dan yang lebih baru Analysis Services
Azure Analysis Services
Fabric/Power BI Premium
Kelas DataSource di namespace Microsoft.AnalysisServices.Tabular adalah abstraksi sumber data model tabular yang menentukan jenis dan lokasi data yang diimpor selama operasi refresh data.
Anda dapat menambahkan sumber data ke model tabular dengan membuat instans objek kelas yang berasal dari DataSource, lalu menambahkannya ke koleksi DataSources objek Model. Untuk menerapkan perubahan pada server, panggil Model.SaveChanges() atau Database.Update(UpdateOptions.ExpandFull).
Model tabular mendukung impor data hanya dari sumber data relasional, di mana penyedia data mengekspos data dalam bentuk tabel dan kolom. Dengan demikian, model objek tabular menggunakan kelas ProviderDataSource (berasal dari DataSource) untuk mengekspos kemampuan ini.
Contoh kode: menambahkan sumber data
Contoh ini menunjukkan cara membuat instans ProviderDataSource dan menambahkannya ke model data.
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();
}
}
}
Langkah selanjutnya
Dalam model, Anda harus menyiapkan pengikatan data yang memetakan kolom sumber di sumber data ke kolom tujuan dalam model. Anda juga perlu menentukan partisi, minimal satu per tabel, yang menyimpan data. Tautan berikut ini memperlihatkan kepada Anda cara: Membuat tabel, partisi, dan kolom