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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
rshahrabani
Frequent Visitor

Set datasource credentials programmatically

We are building an ISV application that uses Power BI embedding for rendering of Power BI reports.  This application will be distributed to client sites and each will have different database logins (username/password) for all their reports.

 

We need a way to programmatically (and securely) set these datasource credentials at runtime when a user attempts to run the report.  These credentials cannot be appended as parameters to the URL or other insecure methods.

 

Does anyone have a method for doing this dynamically in C#?  Your help is much appreciated.

Ronny

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @rshahrabani,

Maybe you can try to parameterize your connection string based on query parameters, then you can dynamically switch Datasource(same data structure) based on posted query parameters and Datasource credentials.

Using the Power BI Service Parameters to change connection strings (To possibly change between Dev  

power bi embedded, change connection string for direct query 

Power BI Embedded Query Parameters API 

In addition, you can also take a look at the following link to switch between different contents:

Tutorial: Embed Power BI content into an application for your customers 
Regards,

Xiaoxin Sheng

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

HI @rshahrabani,

I'd like to suggest you take a look at gateway update data source api and try to use it to set data source credentials.

Gateways - Update Datasource 

BTW, I don't think it is possible to update credentials every time when the user accesses. Maybe you can try to set dynamic RLS based on username and configure them in user data.

Row-level security with Power BI Embedded 
Regards,

Xiaoxin Sheng

Hi @Anonymous,

 

The Gateways - Update Datasource will modify the credentials on the report residing in the Power BI service, and Row-level security will limit the data to a subset given the username. What we are trying to do is to allow execution of a report's datasource login to be configured for different users.

 

For example, a client site will have 3 databases (development, QA and production) with identical structures (but different data).  The development site will execute the report residing on Power BI service with one set of database credentials (username/password) and the QA site will execute the same report on Power BI service with a different set of credentials. This database login needs to be established at runtime with different credentials for each of these platforms (dev, QA and prod).

 

Is there any way to do this programmatically within our Power BI embedded app?

 

Thanks,

Ronny

Anonymous
Not applicable

Hi @rshahrabani,

Maybe you can try to parameterize your connection string based on query parameters, then you can dynamically switch Datasource(same data structure) based on posted query parameters and Datasource credentials.

Using the Power BI Service Parameters to change connection strings (To possibly change between Dev  

power bi embedded, change connection string for direct query 

Power BI Embedded Query Parameters API 

In addition, you can also take a look at the following link to switch between different contents:

Tutorial: Embed Power BI content into an application for your customers 
Regards,

Xiaoxin Sheng

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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