
Код: Выделить всё
using Microsoft.AnalysisServices.AdomdClient;
using Azure.Identity;
using Azure.Core;
using System;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
// Configuration
string xmlaEndpoint = "powerbi://api.powerbi.com/v1.0/myorg/";
string tenantId = "";
string clientId = "";
string clientSecret = "";
string scope = "https://analysis.windows.net/powerbi/api/.default";
try
{
// Step 1: Acquire access token using ClientSecretCredential (Service Principal)
Console.WriteLine("Acquiring access token with ClientSecretCredential...");
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var tokenRequestContext = new TokenRequestContext(new[] { scope });
var accessToken = (await credential.GetTokenAsync(tokenRequestContext)).Token;
Console.WriteLine("Access token acquired successfully.");
// Step 2: Create connection string (without token in connection string)
string connectionString = $"Data Source={xmlaEndpoint};";
// Step 3: Open ADOMD connection
using (AdomdConnection connection = new AdomdConnection(connectionString))
{
// Apply the access token manually using SessionID
connection.SessionID = accessToken;
Console.WriteLine("Opening connection to XMLA endpoint...");
connection.Open();
// Step 4: Execute DAX Query
string query = "SELECT [Name] FROM $SYSTEM.TMSCHEMA_TABLES";
using (AdomdCommand command = new AdomdCommand(query, connection))
{
Console.WriteLine("Executing query...");
using (AdomdDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(reader[0]); // Print first column (adjust as needed)
}
}
}
connection.Close();
Console.WriteLine("Connection closed successfully.");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
}
Я уже пробовал:
Код: Выделить всё
POST https://api.powerbi.com/v1.0/myorg/datasets/{datasetId}/executeQueries
Подробнее здесь: https://stackoverflow.com/questions/793 ... id-and-sec