Board index » cppbuilder » Database not saved when Windows shuts down

Database not saved when Windows shuts down

I am developing an embedded application for Windows 2000 Pro that allows the
user to shut down the computer/system from the GUI.   My problem is that any
changes made to my TDatabase are not saved when windows shuts down.   If the
program only is closed in the normal way, the database changes are intact
upon the next execution.

Here is the code I am using to shut down Windows:

  // The following code is from Microsoft MSDN Library online.

  HANDLE    hToken;
  TOKEN_PRIVILEGES tkp;

  // Get a token for this process.

  if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES |
TOKEN_QUERY, &hToken))
  {
   Application->MessageBox("OpenProcessToken failed.",       // NoLingua
           "Error",
           MB_APPLMODAL | MB_OK | MB_ICONEXCLAMATION);
  }

  // Get the LUID for the shutdown privilege.

  LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);

  tkp.PrivilegeCount    = 1;         // one privilege to set
  tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

  // Get the shutdown privilege for this process.

  AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);

  // Cannot test the return value of AdjustTokenPrivileges.

  if (GetLastError() != ERROR_SUCCESS)
  {
   Application->MessageBox("AdjustTokenPrivileges failed.",      // NoLingua
           "Error",
           MB_APPLMODAL | MB_OK | MB_ICONEXCLAMATION);
  }

  // Shut down the system and force all applications to close.

  if (!ExitWindowsEx(EWX_SHUTDOWN, 0))
   Application->MessageBox("Unable to shut down the printer.",
           "Error",
           MB_APPLMODAL | MB_OK | MB_ICONEXCLAMATION);

When Windows is shutdown is my program terminated in some way that is not
normal termination?  (It appears to be)

Is there any way to force the Database to save itself before this shutdown?
I assumed that after my changes to the database are Posted, that they are
saved to disk immediately, but obviously not.    This will also be a problem
for my application if power is removed from the device unexpectedly.

All help will be greatly appreciated.

Joseph F. Muscarella
Software Engineer / Network Administrator
-----------------------------------------------
InfoSight Corporation, Chillicothe Ohio 45601
j...@infosight.com    * http://www.infosight.com
Phone: 740-642-3600  * Fax: 740-642-5001
"The world is, for the most part, a collective madhouse, and
practically everyone, however 'normal' his facade, is faking sanity." - John
Astin

 

Re:Database not saved when Windows shuts down


Hi,
if youare running BDE as datasbase, you have two different ways to force
database to write data to HDD:
1. set LocalShare = true in BDE configuration
2. call DbiSaveChanges function in TTable's AfterPost event.
Eero
PS. Sorry Joseph for sending this to your e-mail, I managed to push wrong
button...
Eero

Re:Database not saved when Windows shuts down


Eero,

Thanks for the suggestions, number 2 worked fine.   I would have thought
that TTable would have a method to perform this function.

Joseph F. Muscarella
Software Engineer / Network Administrator
-----------------------------------------------
InfoSight Corporation, Chillicothe Ohio 45601
j...@infosight.com    * http://www.infosight.com
Phone: 740-642-3600  * Fax: 740-642-5001
"The world is, for the most part, a collective madhouse, and
practically everyone, however 'normal' his facade, is faking sanity." - John
Astin

Quote
"eero" <e...@vesiir.ee> wrote in message news:3cb6e750$1_1@dnews...
> Hi,
> if youare running BDE as datasbase, you have two different ways to force
> database to write data to HDD:
> 1. set LocalShare = true in BDE configuration
> 2. call DbiSaveChanges function in TTable's AfterPost event.
> Eero
> PS. Sorry Joseph for sending this to your e-mail, I managed to push wrong
> button...
> Eero

Re:Database not saved when Windows shuts down


"Joseph F. Muscarella" <j...@infosight.com> wrote in message
news:3cb6e37b$1_2@dnews...

Quote
> Is there any way to force the Database to save itself before this
shutdown?
> I assumed that after my changes to the database are Posted, that they are
> saved to disk immediately, but obviously not.    This will also be a
problem
> for my application if power is removed from the device unexpectedly.

Hi Joe,

You could try  TTable->FlushBuffers() which would post all data immediately
to disk but you'd need to call TTable->Close() to actually update the time
stamp on the files.

Ed

Other Threads