【发布时间】:2023-01-31 06:42:43
【问题描述】:
我尝试构建从 Power BI 数据集中获取一些数据的 Azure Function, 我是按照这个做的https://learn.microsoft.com/en-us/analysis-services/tom/tom-pbi-datasets?view=sql-analysis-services-2022
我收到错误:异常:Microsoft.AnalysisServices.ConnectionException:连接字符串无效。 ---> System.FormatException:输入字符串的格式不正确。
我尝试了几件事但没有成功。 我有应用程序注册,可以完全访问工作区并可以通过 REST API 执行操作,并且工作区是 PPU 工作区,因此启用了 XMLA 端点并定义了所有权限。
我尝试了几个连接字符串我会列出所有的
连接字符串应该是什么,或者我还缺少其他东西?
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using Microsoft.AnalysisServices.Tabular;
using System;
using RestSharp;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Net.Http;
namespace GetRLSDetails
{
public class Function1
{
private readonly ILogger _logger;
public Function1(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<Function1>();
}
[Function("Function1")]
[Obsolete]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
string datasetname = Environment.GetEnvironmentVariable("datasetname");
string tenantId = Environment.GetEnvironmentVariable("tenantId");
string appId = Environment.GetEnvironmentVariable("appId");
string appSecret = Environment.GetEnvironmentVariable("appSecret");
string workspaceConnection = $"powerbi://api.powerbi.com/v1.0/{tenantId}/BI Management TEST";
Server server = new Server();
//first version
string connectStringUser = $"Provider = MSOLAP;Data source = {workspaceConnection};initial catalog={datasetname};User ID=app:{appId};Password={appSecret};";
//second version
string connectStringUser = $"Provider = MSOLAP;Data Source ={workspaceConnection};Initial Catalog ={datasetname};User ID =app:{appId}@{tenantId}; Password ={appSecret}; Persist Security Info = True; Impersonation Level = Impersonate";
//third version
string connectStringUser = $"Provider=MSOLAP;Data Source={workspaceConnection};User ID=app:{appId}@{tenantId};Password={appSecret};";
//fourth version
string connectStringUser = $"Data Source={workspaceConnection};User ID=app:{appId}@{tenantId};Password={appSecret};";
//using PBI access token
string connectStringUser = $"Provider=MSOLAP;Data Source={workspaceConnection};UserID=;Password={accessToken};";
server.Connect(connectStringUser);
string response_text = "";
foreach (Database database in server.Databases)
{
response_text= response_text+database.Name+',';
}
response.WriteString(response_text);
return response;
}
【问题讨论】:
标签: c# powerbi azure-functions ssas ssas-tabular