Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

[C++] How to recovery dirty ESE file

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

808 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