react-native-sqlite-storage icon indicating copy to clipboard operation
react-native-sqlite-storage copied to clipboard

Error: Could not open database

Open zhangsx9233 opened this issue 7 years ago • 7 comments

Hello, I would like to generate sqlite file in the specified directory, the first run, sqlite file does not exist, you need to create automatically. I have tried many ways.

  • Option One: Error: Could not open database. SQLiteStorage.openDatabase({name: '/mnt/shared/test/testSqlite.db'},()=>{this._successCB('open');},(err)=>{this._errorCB('open',err);}); DEBUG Message 1

  • Option Two: can not continue to run, stay here. SQLiteStorage.openDatabase({name: "testSqlite.db",createFromLocation: "/mnt/shared/test/testSqlite.db"},()=>{this._successCB('open');},(err)=>{this._errorCB('open',err);}); DEBUG Message image

Please help to solve, thank you very much!

zhangsx9233 avatar Feb 02 '18 10:02 zhangsx9233

Were you able to solve it? Did your db already exist before you tried opening it?

ToJen avatar Mar 23 '18 12:03 ToJen

Any updates on this issue?

andpor avatar May 18 '18 10:05 andpor

You cannot open ANY database location. See the documentation on openDatabase and see what is supported. You have to bundle your pre-populated database in the app asset. Also, have a look at the output of the debug console in your IDE...it will print more details debugging information as the application runs from it...

andpor avatar May 18 '18 18:05 andpor

@andpor what's the rationale behind disallowing to open databases from any location?

byohay avatar Jun 22 '18 18:06 byohay

I follow the below blog to integrate SQLite storage

for SQLite DB in android, we have to put on the assets folder.

https://medium.com/infinitbility/react-native-sqlite-storage-422503634dd2

Satur-nity avatar Apr 02 '20 05:04 Satur-nity

I finally managed to solve it, it was because of the use of "SQLite bundled with this library", just enough that of the react-native.config.js file

Screen Shot 2022-07-06 at 3 27 22 PM

Just remove it and work for me in android.

jojemapa avatar Jul 06 '22 19:07 jojemapa