dbTalk Databases Forums  

Error in opening Environment, and cannot create a DB file!

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss Error in opening Environment, and cannot create a DB file! in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
lesslielee@gmail.com
 
Posts: n/a

Default Error in opening Environment, and cannot create a DB file! - 04-01-2007 , 09:31 PM






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;
}


Reply With Quote
  #2  
Old   
Florian Weimer
 
Posts: n/a

Default Re: Error in opening Environment, and cannot create a DB file! - 04-02-2007 , 12:10 AM






Quote:
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>


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.