cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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

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

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

View solution in original post

4 REPLIES 4
Helper II
Helper II

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.

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

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

View solution in original post

Community Support
Community Support

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.

 

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors