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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Connecting to PowerBI with c#

Hi,
am trying to set-up a little c# script to be run in an SSIS package to refresh dataset(s) after the ETL part of the solution has updated the DB.

 (code will be repeated in several ETL processes)
am initially just doing a proof-of-concept as a WindowsForms app (easier to work with).
Following code works....

string workspaceConnection = "powerbi://api.powerbi.com/v1.0/myorg/ProofOfConcept Test";
string userId = "UserName@myOrg.com";
string password = "123456";
string connectStringUser = $"DataSource={workspaceConnection};User ID={userId};Password={password};";

Server server = new Server();
server.Connect(connectStringUser);

foreach (Database database in server.Databases)
{
database.Model.RequestRefresh(RefreshType.DataOnly);
database.Model.SaveChanges();
}

but I have a problem with the userid / password
i enter my credentials - the app accepts these and asks for a password (even tho i have entered one as in example)
is it possible to enter the password into the connection string ??
also - we are using Multi-Factor Auth - can this be bypassed on do we need a user specificslly setup to avoid MFA
thx

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

AFAIK,  power bi already provides the rest API for these operations, I'd like to suggest you use API to do manage power bi contents.

Getting Started with the Power BI API – Querying the Power BI REST API Directly (with C#) – Jeff Pries (jpries.com)

In addition, you can also take a look at the following link about use C# to manage power bi if helps:

C# Application that Manages Power BI - Microsoft Power BI Community

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

AFAIK,  power bi already provides the rest API for these operations, I'd like to suggest you use API to do manage power bi contents.

Getting Started with the Power BI API – Querying the Power BI REST API Directly (with C#) – Jeff Pries (jpries.com)

In addition, you can also take a look at the following link about use C# to manage power bi if helps:

C# Application that Manages Power BI - Microsoft Power BI Community

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.