Skip to main content
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Regular Visitor

Connecting through c#



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 is a 2 way authentication process in my team, the code can't run from a machine. 

I want to use a token instead. Will this remove the need for the other authentication?

If so - what is the proper way to connect with the token?

I succeeded on getting the token, but I can't find the proper way to connect with it.


Right now the code looks like -



                Microsoft.AnalysisServices.Server server = new Microsoft.AnalysisServices.Server();

                    server.Connect(string.Format("Data source={0};", serverName));


What am I missing?


Community Support
Community Support

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 (


Azure Analysis Services: How to open a connection from .NET | endjin - Azure Data Analytics Consulta...

c# - How to authenticate with Azure Analysis Services from Azure batch and data factory

var authority = "<tenant-id>";
var resource = "";
var appId = "***";
var appSecret = "***";

AuthenticationContext authContext = new AuthenticationContext(authority);
ClientCredential credentials = new ClientCredential(appId, appSecret);
var task = authContext.AcquireTokenAsync(resource, credentials);
string token = task.Result.AccessToken;

var connectionStringTemplate = "Provider=MSOLAP;Data Source=asazure://;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();

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources


Fabric certifications survey

Certification feedback opportunity for the community.


Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.