Solved

[C++] How to recovery dirty ESE file

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

746 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

12 Experts available now in Live!

Get 1:1 Help Now