Solved

[C++] How to recovery dirty ESE file

Posted on 2013-12-30
4
742 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 76
base64 decode encode 12 119
Currency Conversion? 1 68
Issues with C++ Class 19 78
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

930 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now