My favorites | Sign in
Project Home Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 949: Creation of database with static SQLiteDatabase methods fails
29 people starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----


Sign in to add a comment
 
Reported by tomgibara, Oct 9, 2008
Reported against SDK 1.0 r1.

The following method call succeeds when opening or creating a database:

context.openOrCreateDatabase("sample.db", MODE_PRIVATE, null);

Whereas the following method call succeeds when opening a database but 
fails on creation:

SQLiteDatabase.openOrCreateDatabase(context.getDatabasePath("sample.db"), 
null);

as do all of the related static database opening methods provided by SQLiteDatabase, with an error via logcat similar to:

ERROR/Database(283): 
sqlite3_open_v2("/data/data/com.tomgibara.android.dbtest/databases/sample.d
b", &handle, 6, NULL) failed

Followed by a stack trace whose root cause begins with:

ERROR/AndroidRuntime(283): Caused by: 
android.database.sqlite.SQLiteException: unable to open database file
ERROR/AndroidRuntime(283):     at 
android.database.sqlite.SQLiteDatabase.dbopen(Native Method)


Oct 31, 2008
#1 firstfan
I guess that's because of the database dir is not created yet. 
In context.openOrCreateDatabase() API, it will check and mkdir first.
Aug 26, 2009
#2 jbq+legacy@google.com
(No comment was entered for this change.)
Labels: Component-Framework
Sep 19, 2009
#3 jbq+legacy@google.com
(No comment was entered for this change.)
Labels: Subcomponent-Storage
Feb 28, 2010
#4 ryu.ten...@gmail.com
I'm having a similar issue SQLiteDatabase db =
SQLiteDatabase.openOrCreateDatabase("db",null); as well... i browse to the
data/data/project folder and there is no database folder and it throws an "unable to
open database file" SQLiteException for me as well... I can't extend Activity from
this class so any ideas?
Oct 6, 2010
#6 nexusani...@gmail.com
I am also getting same problem

Here my code is:

JobDatabaseHelper jobDB = new JobDatabaseHelper(getApplicationContext());
 Cursor c = jobDB.fetchByLocation();


Error:
 ERROR/Database(661): sqlite3_open_v2("/sdcard/iMomentous/careers.db", &handle, 6, NULL) failed

ERROR/JobListDB(661): create database got SQLite Exception: android.database.sqlite.SQLiteException: unable to open database file


JobDatabaseHelper.java
10.1 KB   View   Download
Oct 28, 2010
#7 cfan...@gmail.com
I also hit this errors, the log in logcat is:

10-29 02:12:49.668: ERROR/Database(16124): sqlite3_open_v2("/data/data/com.uppowerstudio.chapter5.db/databases", &handle, 6, NULL) failed

10-29 02:12:49.688: ERROR/AndroidRuntime(16124): android.database.sqlite.SQLiteException: unable to open database file

In my application the database name is entered by user from UI, then click 'Create' button to create database. I found out a strange thing, if i hardcode the database name in code, it's OK, no any errors. But if via EditText.getText() method to get the database and pass it to openOrCreateDatabase method, it's wrong.
Nov 21, 2010
#8 Nicholas...@gmail.com
@cfanboy, That's because getText returns a char array.  Append .toString() to the end of EditText.getText() and that should work right.
Nov 28, 2010
#9 le.dungl...@gmail.com
i have the same issue. I created the database locally and copy it to sdcard. I can open it with some other sqlite tools, but receive errors when trying to open it with SQLiteDatabase.openDatabase methode. And it happens only in Windows (7). It works fine in Linux 
Jan 14, 2011
#10 valle.ke...@gmail.com
Database is exist, but unreadable, checked by that code:
dbFile  = context.getDatabasePath( DATABASE_NAME );
Log.w(TAG, "db "+dbFile.toString()+" exist? "+dbFile.exists()+" readable "+dbFile.canRead());

Jan 14, 2011
#11 valle.ke...@gmail.com
Also reboot does not make that file readable in my case :-(
Jan 25, 2011
#12 *joema...@nextixsystems.com
I am also having this problem. In general I am having a problem with sqlite. I don't know to use the PATH / designated path.

have you solve this problem? please send me you replies to joemarieamparo@yahoo.com

thnaks
Feb 13, 2011
#13 emmanuel...@gmail.com
I had some bug report with this bug.
Now I have this issue as a phone user too.
I described it here :
http://androidblogger.blogspot.com/2011/02/instable-android-and-unable-to-open.html

if someone from google want some more information, please contact me !
Feb 14, 2011
#14 valle.ke...@gmail.com
my steps to reproduce were deleted, so I repeat:
1) Make an app, which uses DB. Run it, let DB be created.
2) Setup sharedUserId in manifest file, upgrade the app without full reinstall.
3) Notice that app folder and DB within is locked.
Feb 17, 2012
#15 robbie.v...@gmail.com
I was also experiencing the same problem. In my case, it turns out that I was causing the problem.

On startup, I would copy my "main.db" database to this.getApplicationInfo().dataDir+"/databases"

The problem with this is main.db was being called databases not being placed in a directory called databases.
I solved the problem by doing this:
File dir = new Fie(this.getApplicationInfo().dataDir+"/databases");
dir.mkdirs();

// then copy my database into the directory.


Jan 9, 2013
#16 m...@thomaskeller.biz
This bug should get more attention. WebView internally also uses one or more SQLite databases and these fail with similar errors:

01-09 16:10:44.993: E/SqliteDatabaseCpp(16613): sqlite3_open_v2("/data/data/com.myproject.myapp/databases/webview.db", &handle, 6, NULL) failed
01-09 16:10:45.033: E/SQLiteDatabase(16613): Failed to open the database. closing it.
01-09 16:10:45.033: E/SQLiteDatabase(16613): android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file
01-09 16:10:45.033: E/SQLiteDatabase(16613): 	at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
01-09 16:10:45.033: E/SQLiteDatabase(16613): 	at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1132)
01-09 16:10:45.033: E/SQLiteDatabase(16613): 	at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1083)
01-09 16:10:45.033: E/SQLiteDatabase(16613): 	at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1059)
01-09 16:10:45.033: E/SQLiteDatabase(16613): 	at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1162)
01-09 16:10:45.033: E/SQLiteDatabase(16613): 	at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1155)
01-09 16:10:45.033: E/SQLiteDatabase(16613): 	at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:835)
01-09 16:10:45.033: E/SQLiteDatabase(16613): 	at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:222)
01-09 16:10:45.033: E/SQLiteDatabase(16613): 	at android.webkit.WebViewDatabase.initDatabase(WebViewDatabase.java:223)
01-09 16:10:45.033: E/SQLiteDatabase(16613): 	at android.webkit.WebViewDatabase.init(WebViewDatabase.java:209)
01-09 16:10:45.033: E/SQLiteDatabase(16613): 	at android.webkit.WebViewDatabase.access$000(WebViewDatabase.java:38)
01-09 16:10:45.033: E/SQLiteDatabase(16613): 	at android.webkit.WebViewDatabase$1.run(WebViewDatabase.java:190)
01-09 16:10:45.038: E/webviewdatabase(16613): openOrCreateDatabase() failed.

and shortly afterwards

01-09 16:10:45.048: E/AndroidRuntime(16613): FATAL EXCEPTION: Thread-2737
01-09 16:10:45.048: E/AndroidRuntime(16613): java.lang.NullPointerException
01-09 16:10:45.048: E/AndroidRuntime(16613): 	at android.webkit.WebViewDatabase.initDatabase(WebViewDatabase.java:232)
01-09 16:10:45.048: E/AndroidRuntime(16613): 	at android.webkit.WebViewDatabase.init(WebViewDatabase.java:209)
01-09 16:10:45.048: E/AndroidRuntime(16613): 	at android.webkit.WebViewDatabase.access$000(WebViewDatabase.java:38)
01-09 16:10:45.048: E/AndroidRuntime(16613): 	at android.webkit.WebViewDatabase$1.run(WebViewDatabase.java:190)


Jan 9, 2013
#17 m...@thomaskeller.biz
I should have mentioned that on the device, where the above exception pops up, an old directory structure was still present. Since the app got a new / specific android:sharedUserId though, this probably was the cause for the issue. I guess purging the user's data completely on re-installation / update of the application is the best way to prevent this.
Mar 16, 2013
#18 duanbo1...@gmail.com
Receive tons of report by this issue. Any plan to resolve it?

Jul 28, 2013
#19 CharlesL...@gmail.com
Hello, i'm having the same issue several days go. I'm using ADT bundle 20130522 before. And this is what i got :

sqlite3_open_v2("/data/data/com.example.test/databases/Mydb", &handle, 6, NULL) failed

The main problem is, there is no Mydb file. I even can't see databases folder from com.example.test. So, i can't do any CRUD things.

This is how i SOLVE it.

Desperately, i try to change the software i used. Now i use the newest one which is Android Bundle 20130717.....

After that, it's completely worked !!!!

That's it... I hope this can solve some problems from certain people.
Good luck and keep trying. Because i know what u feel when it's hard to find solution, it's like ... no solution.... hahaha... Have a nice life (^^)b
Sign in to add a comment

Powered by Google Project Hosting