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
AjithPrasath
Resolver II
Resolver II

Dynamically Change the Database name in the Powerbi desktop

Hi All,

 

   I am trying to  change the database name dynamically in the powerbi from the powerbi rest api call. I created parameters for server and database name  and use that in the query . I am trying to update the database name dynamically from the rest api. But , I am getting the same data  for the database which I given as the default in the parameter name. This is the code where I am updating the datasource name from powerbi rest api. I need to change the database name whatever I am giving as the input. Please help me to resolve this 

// Create UpdateDatasourceRequest to update Azure SQL datasource credentials
UpdateDatasourceRequest req = new UpdateDatasourceRequest {
CredentialDetails = new CredentialDetails(
new BasicCredentials(SqlUserName, SqlUserPassword),
PrivacyLevel.Organizational,
EncryptedConnection.Encrypted)
};
// Execute Patch command to update Azure SQL datasource credentials
pbiClient.Gateways.UpdateDatasource((Guid)gatewayId, (Guid)datasourceId, req);

5 REPLIES 5
AjithPrasath
Resolver II
Resolver II

Hi @lbendlin ,
My requirement is we have multiple customers  and for each customer we have seperate database. So for each customer the report template will be same but we have to dynamically the change the database for each customer so that correct data will be displayed. For implementing this I used - parameters and given dynmaically the database name and server name in the sources. But while calling the report using powerbi rest api , even if I pass different datasource credential - it's still getting the same data for the database which I given as the current value.
Please help me to resolve this

 For implementing this I used - parameters and given dynmaically the database name and server name in the sources. 

You cannot do that.  Use a fixed server and database name for the base connection definition, and then swap out the database name in the custom SQL query.

Thanks for the reply. Can you elaborate on that swap out the database name in the custom sql query?

 

let Source = Sql.Database(server, database1, [Query="Select * from [database2].[schema].[table]"])

 

lbendlin
Super User
Super User

You can only change credentials, you cannot change the connection details.

 

Create a new connection or run a custom SQL that overrides the database name.

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.