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

Can not open database in android

Open lytrunghieu opened this issue 3 years ago • 5 comments

I try to open database with database is located in internal storage on Android. But got error "Could not open database"

my code : const db = await SQLite.openDatabase({name : "app_update", createFromLocation : "/storage/emulated/0/app_update.sqlite"});

error log:

openDatabase {"assetFilename": "/storage/emulated/0/app_update.sqlite", "createFromLocation": "/storage/emulated/0/app_update.sqlite", "dblocation": "nosync", "name": "app_update"} [[Error: Could not open database]]

my package.json:

{
  "name": "awesomeproject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "17.0.2",
    "react-native": "0.67.4",
    "react-native-sqlite-storage": "^6.0.1"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "eslint": "7.14.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.66.2",
    "react-test-renderer": "17.0.2"
  },
  "jest": {
    "preset": "react-native"
  }
}

lytrunghieu avatar Mar 29 '22 08:03 lytrunghieu

Try this

const db = SQLite.openDatabase({name:'app_update',createFromLocation:'~ app_update.sqlite',location:'default'}, openCB, errorCB);

iphonic avatar Mar 29 '22 20:03 iphonic

Hi @iphonic

Try this

const db = SQLite.openDatabase({name:'app_update',createFromLocation:'~ app_update.sqlite',location:'default'}, openCB, errorCB);

I have try it, but it only open database from local app, can not open database from external storage, example: from Download folder in Android

lytrunghieu avatar Mar 30 '22 01:03 lytrunghieu

it

me too

oukin8023 avatar Apr 03 '22 06:04 oukin8023

Hi there, I facing the same issue, is there any way to fix it ? and the error in log said "Could not open database"

BillDelvin avatar Mar 11 '23 03:03 BillDelvin

import RNFetchBlob from 'rn-fetch-blob';

creo que le falta importar el archivo desde el proyecto al dispositivo antes de abrir la DB.

diazbeltran avatar Aug 30 '23 21:08 diazbeltran