Results 1 to 9 of 9

Thread: [RESOLVED] Trouble with inet.openurl after failed connection

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Location
    Manchester, England
    Posts
    6

    Resolved [RESOLVED] Trouble with inet.openurl after failed connection

    Hi,

    I'm writing a little application which uses inet.openURL to bring back a variable from a number of remote systems.

    I've come across a strange issue where if it fails on connection to one of the systems, for the next system it attempts it doesn't seem to do anything at all?

    Here is some example code (I've also uploaded the demo app) where I have 5 different sites to connect to, sites 3 and 4 do not exist.

    If you click on site1, it will bring back a result ok.
    If you click on site3, it will bring back an error ok.
    Now that we've had a failed connection, try clicking either a good or bad site - it does nothing?? It seems to take 2 attempts before it gets the next good or bad result.

    I would really appreciate any help, I've been looking at this for a couple of days and can't see any reason why it's acting in this way.

    Code:
    Private Sub Form_Load()
     Inet1.RequestTimeout = 7
    End Sub
    
    
    Private Sub cmd_check1_Click()
     On Error GoTo Check1Error:
     txt_result1.Text = Inet1.OpenURL(txt_string1.Text)
    Exit Sub
    
    Check1Error:
    txt_result1.Text = Err.Description
    End Sub
    
    
    Private Sub cmd_check2_Click()
     On Error GoTo Check2Error:
     txt_result2.Text = Inet1.OpenURL(txt_string2.Text)
    Exit Sub
    
    Check2Error:
    txt_result2.Text = Err.Description
    End Sub
    
    Private Sub cmd_check3_Click()
     On Error GoTo Check3Error:
     txt_result3.Text = Inet1.OpenURL(txt_string3.Text)
    Exit Sub
    
    Check3Error:
    txt_result3.Text = Err.Description
    End Sub
    
    Private Sub cmd_check4_Click()
     On Error GoTo Check4Error:
     txt_result4.Text = Inet1.OpenURL(txt_string4.Text)
    Exit Sub
    
    Check4Error:
    txt_result4.Text = Err.Description
    End Sub
    
    Private Sub cmd_check5_Click()
     On Error GoTo Check5Error:
     txt_result5.Text = Inet1.OpenURL(txt_string5.Text)
    Exit Sub
    
    Check5Error:
    txt_result5.Text = Err.Description
    End Sub
    Attached Files Attached Files

  2. #2

    Re: Trouble with inet.openurl after failed connection

    please check Inet1.StillExecuting before calling the next site after u have recieved the error

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Location
    Manchester, England
    Posts
    6

    Re: Trouble with inet.openurl after failed connection

    Hi, thanks for the reply.

    I've tried this before I do the submission..

    If Inet1.StillExecuting Then Inet1.Cancel

    It still doesn't make any difference.

    If it was an error (such as attempting a submission while still executing the last one) then the error handler should activate, but it doesn't. It's like it just doesn't process the second attempt.

  4. #4

    Re: Trouble with inet.openurl after failed connection

    the loop should wait till the connection ie till the still executing returns true the application should wait to proceed to the next please visit this url for more clarityhttp://www.vbknowledgebase.com/webap...px?PageCode=44

    try this update me if you need further assistance

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Location
    Manchester, England
    Posts
    6

    Re: Trouble with inet.openurl after failed connection

    Hi,

    Thanks for the help.

    I've put in a loop like in the link you posted..

    Code:
     Do While Inet1.StillExecuting
      DoEvents
      i1 = i1 + 1
      txt_result1.Text = Str(i1)
      If i1 > 50000 Then Inet1.Cancel
    Loop

    I can see that the inet1 is still executing because I see the value for I increasing. It seems to just stick in that loop, even though I set a 7 second timeout on the inet control?

    That is why I then put in the line
    Code:
    If i1 > 50000 Then Inet1.Cancel.
    I thought it would then cancel the previous execution and allow the next one to process - but the loop continues running past 50000?

    Shouldn't the inet1.cancel stop the inet1 from executing and allow the program to leave the loop and process the next command?

  6. #6

    Re: Trouble with inet.openurl after failed connection

    did you check the site i mentioned.

    before opening a ftp location check the ftp operation for still executing.
    if it is not still executing then only do the next operation.


    Code:
        Do While inetFTP.StillExecuting
    
            DoEvents
    
            i = i + 1
    
            '"-doing ls-------" & i
    
        Loop
    
        ' do the rest of the ftp operations here

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Location
    Manchester, England
    Posts
    6

    Re: Trouble with inet.openurl after failed connection

    Yes I did, that's what I put in my previous post.

    What I found is that it would just sit in that loop and never exit, that's why I tried the cancel it if it went on too long.

    I'm doing a HTTP request, not FTP.

    The http request if the unit is online should take under 1 second, it's only returning 1 character.

    If the unit is offline then the inet should timeout after 7 seconds (I've set this on the properties of the inet component).

    Try the code - the units are demo sites I've got online. It will just sit in the loop the first time you try and unit after the previous one failed to connnect.


    Note: I've read that the openURL command is synchronous - and will not move to the next line of code before it's completed? Which makes it even stranger that it sits in that loop?

  8. #8

    Re: Trouble with inet.openurl after failed connection

    Code:
    Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
    Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal pub_lngInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
    Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
    Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
    Private Declare Function GetLastError Lib "kernel32" () As Long
    
    Private Const INTERNET_OPEN_TYPE_DIRECT = 1
    Private Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000
    Private Const INTERNET_SERVICE_Ftp = 1
    Private Const INTERNET_FLAG_RELOAD = &H80000000
    Private Const INTERNET_FLAG_EXISTING_CONNECT = &H20000000
    
    Type FILETIME
            dwLowDateTime As Long
            dwHighDateTime As Long
    End Type
    Type WIN32_FIND_DATA
            dwFileAttributes As Long
            ftCreationTime As FILETIME
            ftLastAccessTime As FILETIME
            ftLastWriteTime As FILETIME
            nFileSizeHigh As Long
            nFileSizeLow As Long
            dwReserved0 As Long
            dwReserved1 As Long
            cFileName As String * 255
            cAlternate As String * 14
    End TypePublic Function IsHavingContent(ByVal strFold As String, _
                                    ByVal strUrl As String, _
                                    ByVal strUname As String, _
                                    ByVal strPwd As String, _
                                    Optional ByRef strErr As String _
                                    ) As Boolean
        Dim lngServHandle As Long
        Dim lngSessHandle As Long
        Dim lngFileHandle As Long
        Dim datFold As WIN32_FIND_DATA
        
        On Error GoTo ErrTrap
        IsHavingContent = False
        
        lngSessHandle = InternetOpen(strUrl, INTERNET_OPEN_TYPE_DIRECT, "", "", INTERNET_FLAG_NO_CACHE_WRITE)
        lngServHandle = InternetConnect(lngSessHandle, strUrl, "21", strUname, strPwd, INTERNET_SERVICE_Ftp, INTERNET_FLAG_EXISTING_CONNECT, &H0)
        lngFileHandle = FtpFindFirstFile(lngServHandle, strFold, datFold, INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_CACHE_WRITE, 0&)
        
        If lngServHandle < 1 Then strErr = "Could not establish connection to ftp server " & strUrl
        InternetCloseHandle lngServHandle
        InternetCloseHandle lngSessHandle
        If lngFileHandle > 0 Then IsHavingContent = True
    ErrTrap:
        If Err Then
            strErr = Err.Description
        End If
    End Function
    i was using the above function to test the content before doing the ftp operation(download or upload). i think in your case you may wish to check lngServHandle to have a value or not(for testing the existance of the location).

    i have tried several times with inet1.cancel but it never get cancelled if the resource is not available that's why i have highlighted that to you not to use the cancel. Actually it will break the loop which we dont like to have.

    and the inetftp is bydefault and will start the ftp operation and goto the next operation it will not wait for the operation to complete.
    in the event of error it hangs

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2007
    Location
    Manchester, England
    Posts
    6

    Red face Re: Trouble with inet.openurl after failed connection

    Thanks Pons,

    I'm using that now to check rather than expecting the inet to handle a missing site.

    It seems Inet in general isn't very good!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width