I use VBA to open an excel file and refresh the power query connections. The code works fine when I'm connecting to a CSV file as the data source but recently I switched the query to a MySQL data source. Since I did that I'm getting "Application-defined or object-defined error" on the .Refresh line.

When I open the file and push refresh on the MySQL connection the query refreshes with no problems. Does something need to be changed?

'''''''GET THE PATH OF THE FILE WITH THE QUERIES TO BE REFRESHED
Public Sub Load_DBSECOND_Path()
    Range("Path_DBSECOND").Value = GetPath()
End Sub

Dim strDBSecond_Path As String
Dim wbDBSecond As Workbook

Dim con As WorkbookConnection
Dim Cname As String

'''''''LOOP THROUGH ALL POWER QUERY CONNECTIONS AND REFRESH ONE AT A TIME UNTIL NO MORE REMAIN
Set wbDBSecond = Workbooks.Open(strDBSecond_Path)

        For Each con In wbDBSecond.Connections
            If Left(con.Name, 8) = "Query - " Then
            Cname = con.Name
                With wbDBSecond.Connections(Cname).OLEDBConnection
                    .BackgroundQuery = False
                    .Refresh
                End With
            End If
        Next