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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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

Anonymous
Not applicable

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

View solution in original post

4 REPLIES 4
GTS_ONE
Advocate II
Advocate 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 

Anonymous
Not applicable

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

v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors