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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

PowerBIClient gets Groups and Reprots but Fails on ExportToFileInGroupAsync

I am able to successfully connect to and run some methods using the PowerBIClient.  However, when I try to actually render the paginated report I get an exception of "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."

 

Here is the full code:

 

 

var accessToken = await tokenAcquisition.GetAccessTokenForUserAsync(new string[] {
	PowerBiScopes.ReadReport,
	PowerBiScopes.ReadDataset,
});

var userInfo = await graphServiceClient.Me.Request().GetAsync();
var userName = userInfo.Mail;

AuthDetails authDetails = new AuthDetails {
	UserName = userName,
	AccessToken = accessToken,
};

var credentials = new TokenCredentials($"{accessToken}", "Bearer");
PowerBIClient powerBIClient = new PowerBIClient(credentials);

var groups = await powerBIClient.Groups.GetGroupsAsync();
var swiftGroup = groups.Value
	.Where(x => x.Name == "SWIFT Application Development")
	.FirstOrDefault();

var swiftReports = await powerBIClient.Reports.GetReportsAsync(swiftGroup.Id);
var s0AuditSheet = swiftReports.Value
	.Where(x => x.Name == "S0 A - Audit Sheet")
	.FirstOrDefault();

var paginatedReportExportConfiguration = new PaginatedReportExportConfiguration {
	ParameterValues = new ParameterValue[] {
		new ParameterValue { Name = "OSCode", Value = "9477"},
	},
	Identities = new List<EffectiveIdentity> { 
		new EffectiveIdentity { Username = "kevin.grigsby@lubrizol.com" },
	}
};

var exportRequest = new ExportReportRequest {
	Format = FileFormat.PDF,
	PaginatedReportConfiguration = paginatedReportExportConfiguration,
};

Export result = null;

try {
	result = await powerBIClient.Reports.ExportToFileInGroupAsync(swiftGroup.Id, s0AuditSheet.Id, exportRequest);
} catch (Exception e) {
	string b = e.Message;
}

return result.Id;

 

 

It gets all the way to the `try` block on the ExportToFileInGroupAsync and then fails with:

 

Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

 

If I go here and click the Try It button I get a 202 response code and the expected output.  What is the problem here?

 

If I need to tack on an EffectiveIdentity or something else I need to see actual code please.  I have been pulling out my hair trying to get this last bit to work for a week now.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Turns out the issue was on our side, more specifically, security/firewall settings. Here is the exact quote from our networking guru.

 

"After some more investigation we determined that our firewall was causing this issue when it was terminating the SSL connection. We were able to add a bypass for the URL and it is now working as expected."

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Turns out the issue was on our side, more specifically, security/firewall settings. Here is the exact quote from our networking guru.

 

"After some more investigation we determined that our firewall was causing this issue when it was terminating the SSL connection. We were able to add a bypass for the URL and it is now working as expected."

v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

Please refer this official documentation to update the codes as below and check whether you can get the expected result.

....
try {
result = await Client.Reports.ExportToFileInGroupAsync (swiftGroup.Id, s0AuditSheet.Id, exportRequest);
} catch (Exception e) {
string b = e.Message;
}

return result.Id;

If you still can't get the expected result, please use the following methods to get the error log and share it with us in order to make troubleshooting.

1. F12

yingyinr_0-1621590512741.png

2. Use fiddler

Test Web API using Fiddler

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.
Anonymous
Not applicable

I am using Blazor here which seems to block/hide those requests.  I have a more detailed and latest info here at Stack Overflow.

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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