Solved

[C++] How to recovery dirty ESE file

Posted on 2013-12-30
4
774 Views
Last Modified: 2014-01-01
Hello Experts,

I could attach ESE database file with followings..

#define _DATPATH "path to db file"

	jet_err = JetGetDatabaseFileInfo(_DATPATH, &db_page_size, sizeof(db_page_size), JET_DbInfoPageSize);
	if (jet_err != JET_errSuccess) {
		return;
	}

	jet_err = JetSetSystemParameter( NULL, NULL, JET_paramDatabasePageSize, db_page_size, NULL);
	if (jet_err != JET_errSuccess) {
		return;
	}

	jet_err = JetSetSystemParameter( NULL, NULL, JET_paramRecovery, 0, "Off");
	if (jet_err != JET_errSuccess) {
		return;
	}

	jet_err = JetCreateInstance(&instance, "instance");
	if (jet_err != JET_errSuccess) {
		return;
	}

	jet_err = JetInit(&instance);
	if (jet_err != JET_errSuccess) {
		JetTerm(instance);
		return;
	}

	jet_err = JetBeginSession(instance, &sesid, 0, 0);
	if (jet_err != JET_errSuccess) {
		JetTerm(instance);
		return;
	}

	jet_err = JetAttachDatabase( sesid, _DATPATH, JET_bitDbReadOnly);
	if (jet_err != JET_errSuccess) {
		JetEndSession(sesid, 0);
		JetTerm(instance);
		return;
	}

Open in new window


But if I tried to open the file that was dirty shutdowned (Application clashed),
JetAttachDatabase returns -550(JET_errDatabaseDirtyShutdown).

I set  JET_paramRecovery to "Off", because if it was set, JetInit failed.

How can I recovery that kind of "dirty shutdowned" file in my program ?
I know eseutil.exe will do that, but I want to do in my apps.

Any advice welcome !

Windows 7 32bit
C++Builder

Nobuo Miwa
0
Comment
Question by:NobMiwa
  • 2
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 500 total points
ID: 39747716
When JetAttachDatabase returns -550, I would system() out a call to eseutil.exe and then re-try the JetAttachDatabase call.
Database utilities do a lot of checking prior to clearing the dirty bits. You don't want to go there.
0
 

Author Comment

by:NobMiwa
ID: 39749177
Hello,

Thank you for advice.

I tried eseutil.exe manually and it works.
But I got some problems..

 - I could not find out 32 bit eseutil.exe that works with the database
   file that was created by Win 7 32bit.
   I tried to open ESE database file that was created with latest Win 7
   32bit system and that was not close clearly. I used eseutil.exe
   that was included in Exchange Server 2007 x86, and got version
   mismatch error. I manually /r(recovery) and /p(repair) with Win7 x64
   and eseutil.exe that was included in Exchange Server 2010 x64
   and works fine.
   I want to work my program with 32/64 bit both. So I need eseutils.exe
   that works with latest 32bit Windows created ESE database file.

 - When I call eseutil.exe with /p (repair), dialogue box pop-upped.
   I don't know how to run without that dialogue box.

Do you have any idea ?
Or is there any way to do with C++ (JetInit()...etc) ?

Any suggestions welcome.

Nobuo Miwa
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 39749241
The only database I've worked with at all much is mysql. My experience there is that it should not matter whether you have 32 or 64 bit program. But if the software revision has changed then you need to run a once-only utility to upgrade the database.
Unless you really really know what you're doing, I would stay away from trying to fix it programatically.
0
 

Author Closing Comment

by:NobMiwa
ID: 39749524
Hello,

I found the solution.

http://managedesent.codeplex.com/discussions/225149

JetInit() could Recovery automatically and silently.

Thank you for the hint.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn different types of Android Layout and some basics of an Android App.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question