Bagikan melalui


Membandingkan replika peluasan skala model semantik

Artikel ini menyediakan beberapa contoh aplikasi Visual Studio untuk membandingkan properti model semantik saat peluasan skala model semantik Power BI diaktifkan.

syncStatus REST API menunjukkan apakah model semantik baca-tulis dan replika baca-saja sinkron. Anda juga dapat menggunakan Model Objek Tabular (TOM) untuk membangun aplikasi kustom yang terhubung ke model semantik dan membandingkan tanda waktu, metadata, dan hasil kueri di antaranya.

Aplikasi 1 - Periksa properti objek database

Gunakan kode di bawah ini untuk membuat aplikasi yang memeriksa properti LastUpdate, LastProcessed , dan LastSchemaUpdate dari model semantik Anda. Sebelum aplikasi melakukan pemeriksaan, aplikasi perlu memanggil Refresh() metode , untuk mendapatkan metadata replika.

Ganti <WorkspaceUrl> dengan URL ruang kerja Anda, dan <Semantic modelName> dengan nama model semantik Anda.

string workspaceUrl = "<WorkspaceUrl>";  // Replace <WorkspaceUrl> with the URL of your workspace
string datasetName = "<Semantic modelName>";  // Replace <Semantic modelName> with the name of your semantic model 
using (var workspace_readwrite = new Microsoft.AnalysisServices.Tabular.Server()) 
using (var workspace_readonly = new Microsoft.AnalysisServices.Tabular.Server()) 
{
    workspace_readwrite.Connect(workspaceUrl + "?readwrite"); 
    workspace_readonly.Connect(workspaceUrl + "?readonly"); 
    var datasetRW = workspace_readwrite.Databases.FindByName(semantic modelName); 
    var datasetRO = workspace_readonly.Databases.FindByName(semantic modelName); 

    if (datasetRW == null || datasetRO == null) 
    { 
        throw new ApplicationException("Database cannot be found!"); 
    }
    datasetRW.Refresh(); 
    datasetRO.Refresh(); 
    Console.WriteLine($"LastUpdated: {datasetRW.LastUpdate} (readwrite) {datasetRO.LastUpdate} (readonly)"); 
    Console.WriteLine($"LastProcessed: {datasetRW.LastProcessed} (readwrite) {datasetRO.LastProcessed} (readonly)"); 
    Console.WriteLine($"LastSchemaUpdate: {datasetRW.LastSchemaUpdate} (readwrite) {datasetRO.LastSchemaUpdate} (readonly)\n"); 
} 
Console.WriteLine("Test completed. Press any key to exit."); 
Console.Read(); 

Aplikasi 2 - Bandingkan metadata model semantik

Gunakan kode di bawah ini untuk membandingkan metadata model semantik baca-tulis utama dengan metadata replika baca-saja. Ganti <WorkspaceUrl> dengan URL ruang kerja Anda, dan <DatasetName> dengan nama model semantik Anda.

string workspaceUrl = "<WorkspaceUrl>";  // Replace <WorkspaceUrl> with the URL of your workspace 
string datasetName = "<DatasetName>";  // Replace <DatasetName> with the name of your semantic model 
using (var workspace_readwrite = new Microsoft.AnalysisServices.Tabular.Server()) 
using (var workspace_readonly = new Microsoft.AnalysisServices.Tabular.Server()) 
{ 
    workspace_readwrite.Connect(workspaceUrl + "?readwrite"); 
    workspace_readonly.Connect(workspaceUrl + "?readonly"); 
    var datasetRW = workspace_readwrite.Databases.FindByName(datasetName); 
    var datasetRO = workspace_readonly.Databases.FindByName(datasetName); 

    if (datasetRW == null || datasetRO == null) 
    { 
        throw new ApplicationException("Database cannot be found!"); 
    } 

    string tmslRW = Microsoft.AnalysisServices.Tabular.JsonSerializer.SerializeDatabase(datasetRW); 
    string tmslRO = Microsoft.AnalysisServices.Tabular.JsonSerializer.SerializeDatabase(datasetRO); 

    if (tmslRW != tmslRO) 
    { 
        Console.WriteLine("The replicas are out of sync.\n"); 
    } 
    else 
    { 
        Console.WriteLine("The replicas are in sync.\n"); 
    } 
} 
Console.WriteLine("Test completed. Press any key to exit."); 
Console.Read(); 

Aplikasi 3 - Mengkueri data model semantik

Gunakan ADOMD.NET untuk mengkueri data dalam replika. Ganti <WorkspaceUrl> dengan URL ruang kerja Anda, dan <DatasetName> dengan nama model semantik Anda.

string workspaceUrl = "<WorkspaceUrl>";  // Replace WorkspaceUrl with the URL of your workspace 
string datasetName = "<DatasetName>";  // Replace DatasetName with the name of your semantic model 
string daxQuery = "Evaluate SUMMARIZECOLUMNS(RefreshTimeTable[Time])"; 
using (var connectionRW = new Microsoft.AnalysisServices.AdomdClient.AdomdConnection()) 
using (var connectionRO = new Microsoft.AnalysisServices.AdomdClient.AdomdConnection()) 
{ 
    connectionRW.ConnectionString = $"Data Source={workspaceUrl}?readwrite;Catalog={datasetName}"; 
    connectionRO.ConnectionString = $"Data Source={workspaceUrl}?readonly;Catalog={datasetName}"; 
    connectionRW.Open(); 
    connectionRO.Open(); 
    var cmd = new Microsoft.AnalysisServices.AdomdClient.AdomdCommand(daxQuery); 
    string resultRW = string.Empty; 
    string resultRO = string.Empty; 
    cmd.Connection = connectionRW; 
    using (var reader = cmd.ExecuteReader()) 
    { 
        while (reader.Read()) 
        { 
            resultRW = reader.GetString(0); 
        } 
    } 

    cmd.Connection = connectionRO; 
    using (var reader = cmd.ExecuteReader()) 
    { 
        while (reader.Read()) 
        { 
            resultRO = reader.GetString(0); 
        } 
    } 

    if (resultRW != resultRO) 
    { 
        Console.WriteLine("The replicas are out of sync.\n"); 
    } 
    else 
    { 
        Console.WriteLine("The replicas are in sync.\n"); 
    } 
} 
Console.WriteLine("Test completed. Press any key to exit."); 
Console.Read();