How to properly closed db when console ends

Hello all,

It seems my Console apps do not close the database properly… er at all!

Under Windoz, in the stop event of a console app, I have this code:
Call App.Db.DB_Close

But the db is always left open!

In the Run event, I have the following code:
While StayAlive = True
Doevents
wend
‘’ Note that on Windows, exiting the Run event
‘’ does NOT terminate a service application. The
‘’ service won’t terminate until the Stop event
‘’ occurs. So to be consistent, let’s just call
‘’ quit with our exit code
Call App.Db.DB_Close
Quit(0)

However, the db never closes…
Can anyone tell me the proper way close a db when a console app is terminated.

Thank you,
Tim

Stop is only for a service, not a service app being run as a console app. A true console app has only one event: Run. Close the db at the end of the Run event. But I would expect Xojo to handle that for you when the app terminates. Has that changed? And is your app terminating cleanly, or crashing?

Hi Tim,

I am using RS 2012 R2.1, running on Win7 Hm Premium; The app terminates cleanly. No crash at all. It appears that either it is not calling the close method .

When testing the console app, it is not running as a service, but will be in production. To test and see the db staying open, I simply click on the ‘x’ to close the app. However the db remains open. Specifically the .db-shm and .db-wal files remain. Normally these are closed also when the db is closed.

Any more ideas?
Thank you,
Tim

Sorry, I wanted to edit the last comments, but cannot figure out how to edit with this new forum!

I tested the app again, while in debug mode. I think the problem is, the code never reaches the call to close the db.

  While StayAlive = True
    Doevents
  wend
        '' Note that on Windows, exiting the Run event
        '' does NOT terminate a service application.  The
        '' service won't terminate until the Stop event
        '' occurs.  So to be consistent, let's just call
        '' quit with our exit code
  Call App.Db.DB_Close
  Quit(0)

I had code in the “Stop” event, but that did not work either - it has been remarked.

How are you stopping the app? Bear in mind that pressing Stop in the debugger is NOT a clean exit. It’s very abrupt, with no clean up happening. I’ve read that testing a service app has improved significantly in 2013r1, but I don’t know any details about how one would go about it.

Hi Tim,

I stop it by clicking the red X in the console app itself. Not in the debugger. I get the same results BTW, when either in debugger or in a compiled app.

Also the super on this is set to “ServiceApplication”
Tim

I don’t see how this code could ever quit cleanly. Pressing the red X closes the shell window that the OS supplies to run your app in. I suspect your app just gets blown away when that happens.

Could someone with experience debugging a service app on Windows chime in here? How do you do it?

You could have a look here .

Thank you Wayne!
I most certainly will do that - thank you for the response and the tool!
Tim