我正在使用 Azure c# .net6 函数应用刷新 Azure 分析服务中的数据模型。我发现连接到分析服务时不支持指定的方法。我的连接字符串看起来正确。我的服务器名称是正确的,初始目录是模型的名称。我使用以下博客作为指南,看起来我正确地执行了连接字符串https://endjin.com/blog/2020/02/azure-analysis-services-how-to-open-a-connection -来自网络
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Microsoft.AnalysisServices.Tabular;
using Azure.Identity;
using System.Threading.Tasks;
namespace refreshModel
{
public static class AnalysisServicesRefreshFunction
{
[FunctionName("AnalysisServicesRefreshFunction")]
public static async Task Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
// Retrieve environment variables
string env = Environment.GetEnvironmentVariable("ENV");
if (string.IsNullOrEmpty(env))
{
throw new InvalidOperationException("ENV environment variable is not found.");
}
// Analysis services details
string serverNamePrefix = "serverNamePrefix";
string serverName = serverNamePrefix + env;
string aasDatabaseName = "aasDatabaseName";
var credential = new DefaultAzureCredential();
var token = await credential.GetTokenAsync(new Azure.Core.TokenRequestContext(new[] { "https://uksouth.asazure.windows.net" }));
var connectionString = $"Provider=MSOLAP;Data Source=asazure://uksouth.asazure.windows.net/{serverName}:rw;Initial Catalog={aasDatabaseName};User ID=;Password={token.Token};Persist Security Info=True;Impersonation Level=Impersonate;";
using (var server = new Server())
{
try
{
server.Connect(connectionString);
}
catch (Exception ex)
{
log.LogError($"An error occurred while connecting to the server: {ex.Message}");
throw;
}
try
{
Database database = server.Databases.FindByName(aasDatabaseName);
if (database == null)
{
throw new InvalidOperationException("Azure analysis services database not found.");
}
Model model = database.Model;
if (model == null)
{
throw new InvalidOperationException("Model not found.");
}
// Refresh the model
model.RequestRefresh(RefreshType.Full);
model.SaveChanges();
log.LogInformation("Data model refresh requested successfully.");
}
catch (Exception ex)
{
log.LogError($"An error occurred while refreshing the data model: {ex.Message}");
throw;
}
}
}
}
}
添加错误日志
使用的包
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="Microsoft.AnalysisServices.NetCore.retail.amd64" Version="19.74.2" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" />
我也添加了正确的权限。我在安全组中有一个 mi 并将该安全组注册为管理员。我已经仔细检查过,它已正确添加为管理员。
我认为它与我传递令牌的连接字符串有关。不知道是否有访问令牌参数。
我也在微软Q和A上发布了同样的问题
并得到微软代理的以下回复
“我在使用持久函数的函数应用程序中遇到了相同的问题和相同的错误。唯一的区别是我使用的是 Microsoft.Identity.Client 而不是 Azure.Identity。原因根据以下网站 https: //www.nuget.org/packages/Microsoft.AnalysisServices.NetCore.retail.amd64#dependency-body-tab 它们是依赖的。我正在使用两个 dll 的最新版本,但它没有什么区别。我我还收到“指定的方法不受支持,而我的笔记本电脑本地一切正常工作”的信息。我将登录 Azure 中的票证寻求支持。如果您能找到此问题的解决方案,可以随时通知我吗?我会这样做也一样。”
收到此错误后,创建了一个检查以查看令牌是否为空,但事实并非如此,因此正在创建令牌。所以不太确定为什么会出现此错误。
更新
尝试删除连接字符串中的可选参数,例如 Security Info=True;Impersonation Level=Impersonate 但仍然出现相同的错误。所以这不是原因。
检查AS防火墙了吗?我遇到了同样的错误,这只是意味着调用实体的 IP 地址不作为允许的地址出现在 AS 防火墙中。
错误消息绝对是可怕的,早期版本的库做得更好,实际上指出不允许使用 IP 地址。但我们不能指望来自一家价值数十亿美元的公司 ofc 发出好的信息。