Using MsgRun along with TRY CATCH (Solved)

Using MsgRun along with TRY CATCH (Solved)

Postby anserkk » Mon Jan 25, 2010 7:43 am

Hi all,

My application connects to a remote database via Internet. I would like to give a message to the user saying that the application is trying to connect to the database via Internet, so that the user is aware what is happening in the background and thus avoid the feeling that the app is struck and hang while it is trying to connect to the database.

This is my code which connects to the the remote database via ADO
Code: Select all  Expand view
TRY
   oApp:oConnection:Open()
CATCH oError
   CursorArrow()
   MsgInfo("Failed to Connect to the Database available in the Internet."+CRLF+;
              "Please check whether internet is available or not in your PC","Connection failed")
   ShowSqlError(oError)
   RETURN .F.
END


I tried using MsgRun to show a message to the user while trying to connect. The code is given below
Code: Select all  Expand view
TRY
   MsgRun("Connecting to the server via Internet","Please wait",{ || oApp:oConnection:Open() } )
CATCH oError
   CursorArrow()
   MsgInfo("Failed to Connect to the Database available in the Internet."+CRLF+;
              "Please check whether internet is available or not in your PC","Connection failed")
   ShowSqlError(oError)
   RETURN .F.
END


If the Internet connection is OK and the connection to the database is successful everything works fine as expected. But if there is a problem with the Internet or database connection, my app will wait indefinitely displaying the wait message.

I need to use TRY CATCH to trap the error. I understand that MsgRun will wait until the code block command is executed, so this will effect TRY CATCH method

Is there any other method to overcome this problem ?

Thanks & Regards
Anser
Last edited by anserkk on Mon Jan 25, 2010 8:46 am, edited 1 time in total.
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Using MsgRun along with TRY CATCH

Postby nageswaragunupudi » Mon Jan 25, 2010 8:25 am

TRY ..CATCH ..END should be within the codeblock that is executed by MsgRun.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10627
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Using MsgRun along with TRY CATCH

Postby anserkk » Mon Jan 25, 2010 8:45 am

Dear Mr.Rao,

Thanks. You are right. The trick worked.

Regards
Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Using MsgRun along with TRY CATCH (Solved)

Postby driessen » Mon Jan 25, 2010 1:12 pm

Please, could you put an example here with the complete solution ?

Thanks a lot in advance.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Using MsgRun along with TRY CATCH (Solved)

Postby anserkk » Tue Jan 26, 2010 2:33 am

Dear Mr.Michel,

This is what I have done.
Code: Select all  Expand view
...
lOk:=.F.
MsgRun("Trying to connect to the Database","Please wait..",;
             { || lOk:=OpenConnection() } )

if !lOk
   MsgInfo("Failed to Connect to the Database available in the Internet."+CRLF+;
              "Please check whether internet is available in your PC","Connection failed")
Endif
..
..
*-----------------------------------*
Function OpenConnection()
*-----------------------------------*
TRY
   oApp:oConnection:Open()
CATCH oError
   CursorArrow()
   ShowSqlError(oError)
   RETURN .F.
END
Return .T.


Regards
Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Using MsgRun along with TRY CATCH (Solved)

Postby driessen » Tue Jan 26, 2010 9:40 am

Thank you very much.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Using MsgRun along with TRY CATCH (Solved)

Postby James Bott » Tue Jan 26, 2010 6:21 pm

Anser,

You may also find this function useful.

Regards,
James



Code: Select all  Expand view
/*
   Name       : IsInternet()  -> lConnected
   Description: Verify connection to Internet
   Syntaxis   : IsInternet(<cServer>)
   Date       : 9 March 2002
   Autor      : Jorge Mason Salinas
                htcsoft
                www.htcsoft.cl
*/


FUNCTION IsInternet(cServer) //Check Internet and any Server

  LOCAL oDummySock := TSocket():New(80) // Maybe any port, only for
WSAStartup()
  LOCAL lConnected

  DEFAULT cServer := "microsoft.com"

  lConnected = ( GetHostByName(cServer) <> "0.0.0.0" )

  oDummySock:End() // Only for WSACleanUp()

RETURN lConnected
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Using MsgRun along with TRY CATCH (Solved)

Postby anserkk » Wed Jan 27, 2010 6:04 am

Dear Mr.James,

Thank you for the information :)

Regards
Anser
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Using MsgRun along with TRY CATCH (Solved)

Postby Antonio Linares » Wed Jan 27, 2010 7:21 am

James, Anser,

FWH already provides IsInternet() --> lYesNo
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 84 guests