Forum Discussion
sonsi
2 years agoRegular Visitor
Connecting through c#
Hi, I am using code that was written for Microsoft Analysis Service, I changed my connection string to another server which is holding PBI Datasets inside. The code seems to work, but since there...
Anonymous
2 years agoNot applicable
Hi sonsi ,
You can refer the following links to connect to an Analysis Services server using a token in C#:
Get the access token:
How to get Azure Access Token using C# - JD Bots (jd-bots.com)
Connection:
c# - How to authenticate with Azure Analysis Services from Azure batch and data factory
var authority = "https://login.windows.net/<tenant-id>";
var resource = "https://southcentralus.asazure.windows.net";
var appId = "***";
var appSecret = "***";
AuthenticationContext authContext = new AuthenticationContext(authority);
ClientCredential credentials = new ClientCredential(appId, appSecret);
var task = authContext.AcquireTokenAsync(resource, credentials);
task.Wait();
string token = task.Result.AccessToken;
var connectionStringTemplate = "Provider=MSOLAP;Data Source=asazure://southcentralus.asazure.windows.net/xxxxxx;Initial Catalog= xxx;User ID=;Password={0};Persist Security Info=True;Impersonation Level=Impersonate";
var connectionString = string.Format(CultureInfo.InvariantCulture, connectionStringTemplate, token);
var server = new Server();
server.Connect(connectionString);
Best Regards