Discussion:
Error in opening Environment, and cannot create a DB file!
(too old to reply)
l***@gmail.com
2007-04-02 02:31:45 UTC
Permalink
I used simple code below, almost same as that mentioned in the BDB's
document.
My system is Linux, BDB 4.5.2, the error is : "Environment open
failed: Invalid argument". The directory "/BDB_env" I have maked. The
same error also appeared on my virtrual machine. So, I think that is
not the problem of my system.
But why? I can't open an environment, and last week I cannot create a
DB file on my disk (I did not use environment that time)?

Please help me!!!

Below is my code:

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <db.h>
#define DATABASE "testDB.db"


int main()
{
DB_ENV *myEnv;
DB *dbp;
DBT key, data;
int ret,t_ret;
u_int32_t env_flags;

//........... Create an environment object and initialize it for error
reporting
ret = db_env_create(&myEnv, 0);
if (ret != 0)
{
fprintf(stderr, "Error creating env handle: %s\n", db_strerror(ret));
return -1;
}

//........If the environment does not exist create it. Initialize the
in-memory cache.
env_flags = DB_CREATE | DB_INIT_MPOOL;

//........Open the environment.
ret = myEnv->open(myEnv,"/BDB_env",env_flags,0);
if (ret != 0)
{
fprintf(stderr, "Environment open failed: %s", db_strerror(ret));
return -1;
}



if ((ret = db_create(&dbp, myEnv, 0)) != 0)
{
fprintf(stderr, "db_create: %s\n", db_strerror(ret));
exit (1);
}


if ((ret = dbp->open(dbp, NULL, DATABASE, NULL, DB_BTREE, DB_CREATE,
0664)) != 0)
{
dbp->err(dbp, ret, "%s", DATABASE);
exit (1);
}

if (dbp != NULL)
dbp->close(dbp, 0);

//.........close evn
//........When you are done with an environment, you must close it.
//........Before you close an environment, make sure you close any
opened databases
if (myEnv != NULL)
myEnv->close(myEnv, 0);


return 0;
}
Florian Weimer
2007-04-02 05:10:58 UTC
Permalink
Post by l***@gmail.com
But why? I can't open an environment, and last week I cannot create a
DB file on my disk (I did not use environment that time)?
You should switch on verbose error messages to find out why:

<http://www.oracle.com/technology/documentation/berkeley-db/db/ref/debug/runtime.html>
Loading...