diff --git a/build/openldap.m4 b/build/openldap.m4
index f3de824dfd1e9a2cf30d49e7e26128329dc1f11c..7b0acc878385ee6b816402c2857360df2dd1c882 100644
--- a/build/openldap.m4
+++ b/build/openldap.m4
@@ -354,15 +354,21 @@ main()
 
 #ifdef DB_CDB_ALLDB
 	rc = env->set_flags( env, DB_CDB_ALLDB, 1 );
-	if( rc == 0 )
+
+	if( rc ) {
+		printf("BerkeleyDB: %s\n", db_strerror(rc) );
+		return rc;
+	}
 #endif
 
-	{
 #if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1)
-		rc = env->open( env, NULL, flags, 0 );
+	rc = env->open( env, NULL, flags, 0 );
 #else
-		rc = env->open( env, NULL, NULL, flags, 0 );
+	rc = env->open( env, NULL, NULL, flags, 0 );
 #endif
+
+	if ( rc == 0 ) {
+		rc = env->close( env, 0 );
 	}
 
 	if( rc ) {
@@ -370,12 +376,6 @@ main()
 		return rc;
 	}
 
-#if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1)
-	env->remove( env, NULL, DB_FORCE );
-#else
-	env->remove( env, NULL, NULL, DB_FORCE );
-#endif
-
 #else
 	DB_ENV env;
 	memset( &env, '\0', sizeof(env) );
diff --git a/configure b/configure
index 011b4a72484b8fb5d4ef39300a022112eb89c2a0..c315a36eb4e46c4250df7ded526c4d38e213c79c 100755
--- a/configure
+++ b/configure
@@ -12921,15 +12921,21 @@ main()
 
 #ifdef DB_CDB_ALLDB
 	rc = env->set_flags( env, DB_CDB_ALLDB, 1 );
-	if( rc == 0 )
+
+	if( rc ) {
+		printf("BerkeleyDB: %s\n", db_strerror(rc) );
+		return rc;
+	}
 #endif
 
-	{
 #if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1)
-		rc = env->open( env, NULL, flags, 0 );
+	rc = env->open( env, NULL, flags, 0 );
 #else
-		rc = env->open( env, NULL, NULL, flags, 0 );
+	rc = env->open( env, NULL, NULL, flags, 0 );
 #endif
+
+	if ( rc == 0 ) {
+		rc = env->close( env, 0 );
 	}
 
 	if( rc ) {
@@ -12937,12 +12943,6 @@ main()
 		return rc;
 	}
 
-#if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1)
-	env->remove( env, NULL, DB_FORCE );
-#else
-	env->remove( env, NULL, NULL, DB_FORCE );
-#endif
-
 #else
 	DB_ENV env;
 	memset( &env, '\0', sizeof(env) );