Forum Discussion
Using Tabular ProviderDataSource with On Premise PowerBi Data Gateway DB Connection
I was finally able to get this working end to end, at least in my scenario.
Possible caveats: I am using a service account (not principle) for this automation. The same user was used to: configure the gateway datasource, write the dataset to the Power BI workspace, and interact with the Power BI REST interface.
According to Microsoft, the XMLA endpoing used to write TOM to Power BI Premium does not allow a datasource to be bound at the time of upload. However, the datasource information needs to be included with the dataset upload. Credentials cannot be bound in this step and so are no required.
Example:
Database database = new Database({DATASET_NAME});
database.CompatibilityLevel = 1500;1500
pbiServer.Databases.Add(database);
model = new Model();
database.Model = model;
ProviderDataSource datasource = new ProviderDataSource()
{
Name = {DATASET_NAME},
Description = {DATASET_NAME},
ConnectionString = "Provider=SQLNCLI11;Persist Security Info=False;Data Source={SQL_SERVER};Initial Catalog={SQL_DATABASE}",
};
model.DataSources.Add(datasource);
After the dataset is written to the Power BI workspace, it will need to be bound to the gateway datasource. I was able to do this through the rest interface:
URL
https://api.powerbi.com/v1.0/myorg/groups/{WORKSPACE_ID}/datasets/{DATASET_ID}/Default.BindToGateway
BODY
{ "gatewayObjectId": "{GATEWAY_ID}", "datasourceObjectIds": [ "{GATEWAY_DATASOURCE_ID}" ] }
URL
https://api.powerbi.com/v1.0/myorg/groups/{WORKSPACE_ID}/datasets/{DATASET_ID}/refreshes
BODY
{ "notifyOption": "none" }
A 404 on the first call indicates it was not able to identify the datasource in the dataset to bind to the provided gateway datasource ID and the datasource added to the TOM during the dataset upload is either incorrect or does not match the server/database of the gateway datasource configured.