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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Error when refreshing dataset via REST API in VB.net

Hello,

 

I'm using the following code to trigger a dataset refresh via the REST API and VB.net:

 

      Dim redirectUri, resourceUri, authorityUri, clientID As String

        redirectUri = "https://dev.powerbi.com/Apps/SignInRedirect"

        resourceUri = "https://analysis.windows.net/powerbi/api"

        authorityUri = "https://login.windows.net/common/"

        Dim authContext As New AuthenticationContext(authorityUri, New TokenCache())

        clientID = My-Client-ID

        Dim authenticationResult As AuthenticationResult

        Try

            authenticationResult = Await authContext.AcquireTokenAsync(resourceUri, clientID, New Uri(redirectUri), New PlatformParameters(PromptBehavior.Auto))

            Dim s As HttpWebRequest
            Dim enc As UTF8Encoding
            Dim postdata As String

            s = HttpWebRequest.Create("https://api.powerbi.com/v1.0/myorg/groups/My-Workspace/datasets/My-Dataset/refreshes")

            s.Method = "POST"
            s.KeepAlive = True
            s.ContentLength = 0

            s.Headers.Add("Authorization", String.Format("Bearer {0}", authenticationResult.AccessToken))
            s.ContentType = "application/x-www-form-urlencoded"

            s.GetResponse()

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

 

This used to work perfectly. However suddenly I started to get an error at .GetResponse ("Connection closed..."). Does anyone have an idea where the problem could be? I updated all the involved nuget packages but that didn't help.

 

Thanks for any help!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

In case anyone is having the same issue, I had to enable TLS 1.2 for the connection, which I did by adding this line in code:

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12

Reference here and here.

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

In case anyone is having the same issue, I had to enable TLS 1.2 for the connection, which I did by adding this line in code:

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12

Reference here and here.

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.