cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Connection closed when using the Invoke-PowerBIRestMethod to refresh dataset

We have a PowerShell script that uses the "Invoke-PowerBIRestMethod" to force a dataset to refresh.  The script has been working without issues for the past several months.  For the last week and a half, we have started receiving the error stating the connection was closed by the host.  At first it was very random but then in the last couple of days, the error is occurring consistently.

 

We pass in the workspace GUID, dataset GUID, and the file path that stores the password for the user. 

 

I have included a portion of our script (it uses parameters to pass in the workspace GUID, dataset GUID, and the file path that stores the password for the user) and the full error message below.

 

Does anyone have any insights as to what the issue could be?

 

Thanks,

----------------------------------------------------------------------------------------------------------

 

Script:

param( [string] $WSIDAdmin, [string] $DSIDRefresh, [string] $PBIKEY )

Set-ExecutionPolicy Unrestricted

 

$passwordFile = $PBIKEY
$username = "EXXXX@xpo.com"
$EBASecurityURL = 'groups/' + $WSIDAdmin + '/datasets/' + $DSIDRefresh + '/refreshes'


$password = Get-Content $passwordFile | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($username, $password)

Connect-PowerBIServiceAccount -Credential $credential

$MailFailureNotify = @{"notifyOption"="MailOnFailure"}
Invoke-PowerBIRestMethod -Url $EBASecurityURL -Method Post -Body $MailFailureNotify }

 

Full error message:

{System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) --- End of inner exception stack trace --- at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.PowerBI.Commands.Common.PowerBISettings.d__6.MoveNext()} Message : One or more errors occurred. Data : {} InnerException : System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) --- End of inner exception stack trace --- at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult) at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.PowerBI.Commands.Common.PowerBISettings.d__6.MoveNext() TargetSite : TResult GetResultCore(Boolean) StackTrace : at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) at Microsoft.PowerBI.Commands.Common.PowerBISettings..ctor(String settingsFilePath) at Microsoft.PowerBI.Commands.Common.PowerBICmdlet.GetDefaultInitFactory() at lambda_method(Closure ) at System.Management.Automation.CommandProcessor.Init(CmdletInfo cmdletInformation) HelpLink : Source : mscorlib HResult : -2146233088
Invoke-PowerBIRestMethod -Url groups/03752544-651f-4269-b117-92bba89fd007/datasets/99b9b70b-509c-4a66-a8f4-0e4eb4d175da/refreshes-Method Post -Body
Connect-PowerBIServiceAccount -Credential System.Management.Automation.PSCredential

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Helper II
Helper II

Re: Connection closed when using the Invoke-PowerBIRestMethod to refresh dataset

For me, looks like this was related to the new TLS requirment.  Adding this to my PS script resolved it:

 

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 

View solution in original post

Highlighted
Frequent Visitor

Re: Connection closed when using the Invoke-PowerBIRestMethod to refresh dataset

You are correct - we discovered that trick as well and it worked for us.

View solution in original post

4 REPLIES 4
Highlighted
Community Support
Community Support

Re: Connection closed when using the Invoke-PowerBIRestMethod to refresh dataset

Hi @Bob_0521 ,

 

You may check if it is the issue for connection in  Power BI Support , and refer to the workaround in it currently. If you still have this issue for Power BI, you'd better create a support ticket in Power BI Support , Scroll down and click "CREATE SUPPORT TICKET", or go to Issue forum  to get further help.

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Highlighted
Helper II
Helper II

Re: Connection closed when using the Invoke-PowerBIRestMethod to refresh dataset

For what it's worth, I think I'm seeing the same thing as of today.

 

I built out a whole series of new scripts on Tue Jun 23rd and had tested them successfully all throughout the day.

 

But as of today (Jun 26th) I'm getting that same "underlying connection was closed..." error.

Highlighted
Helper II
Helper II

Re: Connection closed when using the Invoke-PowerBIRestMethod to refresh dataset

For me, looks like this was related to the new TLS requirment.  Adding this to my PS script resolved it:

 

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 

View solution in original post

Highlighted
Frequent Visitor

Re: Connection closed when using the Invoke-PowerBIRestMethod to refresh dataset

You are correct - we discovered that trick as well and it worked for us.

View solution in original post

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

July 2020 Community Highlights

July 2020 Community Highlights

Learn about the exciting things that happened in July.

Featured Data Story of The Month

Featured Data Story of The Month

All Data Stories Gallery contributions are reviewed for each month. We select a contribution and feature the community member the following month.

Power BI Dev Camp - Developing with .NET Core

Power BI Dev Camp - Developing with .NET Core

Learn how to develop custom web applications for Power BI using .NET Core 3.1 and .NET 5.

Power BI Desktop August 2020 Update

Power BI Desktop August 2020 Update

We have great updates this month! Click the link for the video with more info.

Top Solution Authors
Top Kudoed Authors