SQLite Error: Could not open database

I’m having this error when trying to create a database with SQLite Error: exec proxy not found for :: SQLitePlugin :: open

database-provider.ts

import { Injectable } from '@angular/core';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';

@Injectable()
export class DatabaseProvider {

  constructor(public sqlite: SQLite) {
    this.sqlite.create({
      name: 'data.db',
      location: 'default'
    }).then((db: SQLiteObject) => {
        db.executeSql('create table danceMoves(name VARCHAR(32))', {})
          .then(() => console.log('Executed SQL'))
          .catch(e => console.log(e));
      }).catch(e => console.log(e));
  }

}

app.module.ts

import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { BrowserModule } from '@angular/platform-browser';
import { DatabaseProvider } from '../providers/database-provider'
import { SQLite } from '@ionic-native/sqlite';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    IonicModule.forRoot(MyApp),
    BrowserModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    SQLite,
    DatabaseProvider,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

home.ts

import { Component } from '@angular/core';
import { DatabaseProvider } from '../../providers/database-provider'
import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController, public sqlProvider: DatabaseProvider) {
  }

}

If by chance you’re trying to run this in a browser, it’s not going to happen. Needs to be on device.

1 Like

I got this on console running an android emulator

[20:19:35]  console.log: OPEN database: data.db 
[20:19:35]  console.log: database already open: data.db 
[20:19:35]  console.log: OPEN database: data.db - OK 
[20:19:35]  console.log: Ionic Native: deviceready event fired after 789 ms 
[20:19:35]  console.log: [object Object] 

Does this mean it worked?

1 Like