none
Fixing a crashed ESE db(dirty state) using Jet Blue API RRS feed

  • Question

  • As the title says, using the C++ Jet Blue API, I'm trying to fix a previously crashed DB, with the exception where i have only the EDB file without any logs and checkpoints.

    I've read that JetInit() is supposed to deal with such scenarios, but how exactly does it know which DB to fix if upon execution, it retrieves pointer to INSTANCE?(in the example i switched to JetInit3)

    Regardless my attempts, JetAttachDatabaseW returns with -550, dirty state.

    Only by calling to esentutl /p mydb.dat i was able to fix my DB and open it properly, I'm searching for a more elegant solution which will be executed solely from code and not using system("esentutl /p mydb.dat");

            ULONG unPageSize;
    	long jet_err = JetGetDatabaseFileInfoW(p2.file_string().c_str(), &unPageSize, sizeof(unPageSize), JET_DbInfoPageSize);
    	if (jet_err != JET_errSuccess) {
    		return false;
    	}
    
    	jet_err = JetSetSystemParameter( NULL, NULL, JET_paramDatabasePageSize, unPageSize, NULL);
    	if (jet_err != JET_errSuccess) {
    		return false;
    	}
    
    	jet_err = JetSetSystemParameter( NULL, NULL, JET_paramRecovery, 0, "Off");
    	if (jet_err != JET_errSuccess) {
    		return false;
    	}
    
    	jet_err = JetSetSystemParameter( NULL, NULL, JET_paramLogFilePath, 0, "C:/Users/user/AppData/Local/Temp/db/");
    	if (jet_err != JET_errSuccess) {
    		return false;
    	}
    
    	jet_err = JetSetSystemParameter( NULL, NULL, JET_paramSystemPath, 0, "C:/Users/user/AppData/Local/Temp/db/");
    	if (jet_err != JET_errSuccess) {
    		return false;
    	}
    
    	jet_err = JetSetSystemParameter( NULL, NULL, JET_paramAlternateDatabaseRecoveryPath, 0, "C:/Users/user/AppData/Local/Temp/db/");
    	if (jet_err != JET_errSuccess) {
    		return false;
    	}
    	 
    	jet_err = JetSetSystemParameter( NULL, NULL, JET_paramCircularLog, 1, nullptr);
    	if (jet_err != JET_errSuccess) {
    		return false;
    	}
    
    	jet_err = JetSetSystemParameter( NULL, NULL, JET_paramCreatePathIfNotExist, 1, nullptr);
    	if (jet_err != JET_errSuccess) {
    		return false;
    	}
    	
    	JET_INSTANCE instance = { 0 };
    	jet_err = JetCreateInstance(&instance, "instance");
    	if (jet_err != JET_errSuccess) {
    		return false;
    	}
    
    	std::wstring str = p2.file_string();
    	JET_RSTMAP_W rstmap;
    	rstmap.szDatabaseName = L"";
    	rstmap.szNewDatabaseName = &str[0];
    	JET_RSTINFO_W p = { 0 };
    	p.cbStruct = sizeof(p);
    	p.rgrstmap = &rstmap;
    	p.crstmap = 1;
    	jet_err = JetInit3W(&instance, &p, JET_bitReplayIgnoreLostLogs);
    	if (jet_err != JET_errSuccess) {
    		JetTerm(instance);
    		return false;
    	}
    
    	JET_SESID sesid;
    	jet_err = JetBeginSession(instance, &sesid, 0, 0);
    	if (jet_err != JET_errSuccess) {
    		JetTerm(instance);
    		return false;
    	}
    
    	jet_err = JetAttachDatabaseW( sesid, str.c_str(), JET_bitDbReadOnly); // fails over here
    	if (jet_err != JET_errSuccess) {
    		JetEndSession(sesid, 0);
    		JetTerm(instance);
    		return false;
    	}
    
    Thanks
    Tuesday, November 8, 2016 7:47 AM