ADO and resume laptop

ADO and resume laptop

Postby Marc Vanzegbroeck » Fri Jun 27, 2014 1:18 pm

Hello,

I have a client that use my program on a network. before it was a version with DBF-files. Now I upgrade his program to ADO with MySQL.
The program is working very nice, but...
The customer don't quit the program at the evening, but all the PC go to 'Sleep-mode'. In the morning he resume the program, but than he get directly an error that the program can't write/access the database.
With the DBF-files he didn't get an error, but now he have to restart the program.
I know it's better to quit the program, but is there a way to fix this problem without restaring the program?
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1157
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: ADO and resume laptop

Postby Rick Lipkin » Fri Jun 27, 2014 3:37 pm

Mark

If it were me and your customer does not want to shut down his computer, I would go to the control panel and the power settings and on "Close Lid" .. set the option to "Do Nothing"

That way, your customer and just shut the lid and walk away and the laptop will not go to sleep.

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2629
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: ADO and resume laptop

Postby Marc Vanzegbroeck » Sat Jun 28, 2014 1:57 pm

Hi,

I was thinking to do a open again if it fails

like
Code: Select all  Expand view
TRY
   oSQL:execute( vCommando)
CATCH oErr
   TRY
      oSQL:Open()
   CATCH oError
      MsgInfo("Failed to Connect to the Database ")
      quit
   END
END TRY
 


I'm wondering that is would be a good solution?
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1157
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: ADO and resume laptop

Postby Marc Vanzegbroeck » Sun Jun 29, 2014 8:30 am

Hi,

I just found out that there is a ADO-state-propery, so I can check that the connection is still OK.

I will try to use that.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1157
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: ADO and resume laptop

Postby nageswaragunupudi » Sun Jun 29, 2014 9:20 am

Marc Vanzegbroeck wrote:Hi,

I just found out that there is a ADO-state-propery, so I can check that the connection is still OK.

I will try to use that.

oCn:State --> 0 = not open and 1 = open
But when server disconnects you, your oCn:State shows 1 though in real there is no connection.

To resume a connection you need to do:
Code: Select all  Expand view

oCn:Close()
TRY
   oCon:Open()
CATCH
   // handle failure and exit
END
if oCn:State == 0
   // not connected
else
   // connected .. go ahead
endif
 

When connection dies (due to loss of connectivity or server closing the connection), only way we know it when we get a runtime error. Any openration, even a recordset movement causes runtime eror.

So try to have a global error block directing to your own error routine:
1. Check if it is Ado Error ( check oCn:Errors collection )
2. If Ado error is it related to connection
a. If not call standard error routne
b. If yes, Try Resume connection as above and then return RETRY operation
Regards

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

Re: ADO and resume laptop

Postby Marc Vanzegbroeck » Sun Jun 29, 2014 9:30 am

Thank you Rao,

Indeed, I just found out that oCn:State is still open, even when I disconnected the network.

I try to use your suggestion, and put it in my global error-handler.

The only problem I have ir the network-connections was lost, and back OK-again (after resuming the PC) is when writing to the database, because, for reading I allways use a recordset that I open while reading it. If the connections is back OK, than it works.
But for opdating, writing to the database, I use a connection that I open in the beginning of my program, and close while exiting the program.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1157
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: ADO and resume laptop

Postby nageswaragunupudi » Sun Jun 29, 2014 9:42 am

We are not opening a new connection again. We are closing and reopening the same connection that you opened first. Still do you get error while writing?

Meanwhile please also see
viewtopic.php?f=3&t=26907&start=0&hilit=recordset+local
Regards

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

Re: ADO and resume laptop

Postby Marc Vanzegbroeck » Sun Jun 29, 2014 9:52 am

I know than whe are using the same connection again, but I was refering to recordset that are allways are reopen while calling.

But anyhow, it's working now, like you suggested. By closing the connection, and reopening it, if there was an error.

Thanks,
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1157
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: ADO and resume laptop

Postby nageswaragunupudi » Sun Jun 29, 2014 10:13 am

Glad it is working. Can you post your Code here for the benefit of all of us? Can we standardise this and integrate with fwh adofuncs library?
Regards

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

Re: ADO and resume laptop

Postby Marc Vanzegbroeck » Sun Jun 29, 2014 10:37 am

For now I have put in my functions I have made for myself for updating, deleting and adding records with ADO, because I needed it very fast for that customer.

I will put it in my error-handler, so it will work allways when there is an ADO-error. It will than also write the error in the error-file.
Now the customer just get an error that the connections was lost, and that the program can't reconnect anymore...
I will post the code after I put it in my error handler.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1157
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: ADO and resume laptop

Postby Marc Vanzegbroeck » Mon Jun 30, 2014 8:57 am

Rao,

What I was thinking to do is add this to errorsys.prg
Code: Select all  Expand view
if ErrorMessage( e ) = 'Error ADODB.Connection/16389  E_FAIL: EXECUTE'
   oSQL:Close()
   oSQL:=CreateObject("ADODB.Connection")
   TRY
      oSQL:Open()
      return .f.
   CATCH
      Msgalert( "Error connecting to server")
   END TRY
endif
 
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1157
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: ADO and resume laptop

Postby Marc Vanzegbroeck » Sun Aug 24, 2014 8:12 am

Hi,

After debugging the program, I finaly found the error that my customer get.
It is : 'MySQL server has gone away'

Now I'm looking a for a way to reconnect. I found something like oSql:ping(), fut there is also a possibility to auto-reconnect according to the MySQL-site.
Has anyone already did something like this?
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1157
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 16 guests