[英]Microsoft.AnalysisServices.AdomdClient doesn't work in .Net Core application (Authentication issue)
I've an issue using Microsoft.AnalysisServices.AdomdClient.NetCore.retail.amd64 library in.Net Core Web API application.我在 .Net Core Web API 应用程序中使用 Microsoft.AnalysisServices.AdomdClient.NetCore.retail.amd64 库时遇到问题。
Fun fact : The same code works perfectly fine in.Net 4.7.2 application, but fails in.Net Core (currently I'm testing.Net 5 version).有趣的事实:相同的代码在 .Net 4.7.2 应用程序中运行良好,但在 .Net Core 中失败(目前我正在测试 .Net 5 版本)。
The app has Windows authentication (IIS express) and uses connection string to Analysis service with Integrated Security=SSPI parameter.该应用程序具有 Windows 身份验证(IIS 快速),并使用连接字符串与 Integrated Security=SSPI 参数的分析服务。 On connection.Open() method I'm getting an
在 connection.Open() 方法上我得到一个
Authentication Exception
身份验证异常
"Unable to obtain authentication token using the credentials provided".“无法使用提供的凭据获取身份验证令牌”。 Inner exception: "MsalServiceException": Federated service at url returned
内部异常:“MsalServiceException”:返回 url 的联合服务
error.错误。
Code:代码:
Startup.cs
services.AddAuthentication(IISDefaults.AuthenticationScheme);
Controller private method: Controller 私有方法:
private DataTable GetData(string connectionString, string databaseName, string daxQuery,
Dictionary<string, string> parameters)
{
var dt = new DataTable();
using(var conn = new AdomdConnection(connectionString))
{
//fails here
conn.Open();
conn.ChangeDatabase(databaseName);
using(vad cmd = new AdomdCommand(daxQuery, conn))
{
if(parameters.Any())
{
foreach(var param in parameters)
{
cmd.Parameters(param.Key, param.Value);
}
}
using (var adapter = AdomDataAdapter(cmd))
{
adapter.Fill(dt);
}
}
return dt;
}
}
Update : I've tried the same code in console applications.更新:我在控制台应用程序中尝试过相同的代码。
.Net 4.7.2 app works as expected. .Net 4.7.2 应用程序按预期工作。
.Net 4 fails with different error: .Net 4 失败并出现不同的错误:
AcquireTokenByIntegratedWindowsAuth is not supported on .net core without adding.WithUserName() because MSAL cannot determine the username (UPN) of the currently logged in user. AcquireTokenByIntegratedWindowsAuth 不支持在 .net 核心上不添加。WithUserName() 因为 MSAL 无法确定当前登录用户的用户名 (UPN)。 Please use.WithUserName() before calling ExecuteAsync().
请在调用 ExecuteAsync() 之前使用.WithUserName()。 For more details see https://github.com/AzureAD/microsoft-authentication-library-for-do.net/wiki/Integrated-Windows-Authentication
有关详细信息,请参阅https://github.com/AzureAD/microsoft-authentication-library-for-do.net/wiki/Integrated-Windows-Authentication
It seems that .net core version can't get username and use it to get Azure token for Analysis service authentication.貌似.net核心版无法获取用户名,用它来获取Azure token进行分析服务认证。 Moreover, if I use MSAL library to get the token it is not clear how to use the token with AdomdClient library.
此外,如果我使用 MSAL 库获取令牌,则不清楚如何将令牌与 AdomdClient 库一起使用。
I've already written to library owners, but haven't get any response.我已经写信给图书馆老板,但没有得到任何回应。
After investigation I've found that Microsoft.AnalysisServices.AdomdClient.NetCore.retail.amd64 has some hidden dependency.经过调查,我发现 Microsoft.AnalysisServices.AdomdClient.NetCore.retail.amd64 有一些隐藏的依赖关系。 It works as expectected if you add Microsoft.Identity.Client nuget package to project.
如果将 Microsoft.Identity.Client nuget package 添加到项目中,它会按预期工作。
Another possible solution - don't use AdomdClient and use OleDb connection:另一种可能的解决方案 - 不要使用 AdomdClient 并使用 OleDb 连接:
using (var con = new OleDbConnection(connectionString))
{
con.Open();
con.ChangeDatabase(databaseName);
using (var cmd = new OleDbCommand(query, con))
{
using (OleDbDataAdapter adapter = new OleDbDataAdapter(cmd))
{
// Here we should increase timeout because DAX query execution can be bigger than default 30 seconds
adapter.SelectCommand.CommandTimeout = _timeoutInSeconds;
adapter.Fill(dt);
}
}
return dt;
}
OleDb works as well, you can query Tabular model without a problem. OleDb 也可以正常工作,您可以毫无问题地查询表格 model。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.