Android Question SQLiteCantOpenDatabaseException

Discussion in 'Android Questions' started by wimpie3, Mar 27, 2015.

  1. wimpie3

    wimpie3 Active Member Licensed User

    I'm currently testing an app on several devices.

    One of them, an older HTC, crashes with the following error:
    android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file

    This happens in a module on this line:
    Code:
    SQL.Initialize(File.DirDefaultExternal, "mydb.db"True)
    Since the "true" flag is passed, a new db should be created, but for one reason or another this does not seem to work on this specific device.

    What am I missing?
     
  2. DonManfred

    DonManfred Expert Licensed User

    my guessing: permission to write on external storage?
     
  3. wimpie3

    wimpie3 Active Member Licensed User

    Uhmmm... so why would it work on other machines and not on my HTC?

    Plus, this is what Erel wrote before:

     
  4. DonManfred

    DonManfred Expert Licensed User

    Except if you are using a removepermission
     
  5. wimpie3

    wimpie3 Active Member Licensed User

    Well, I'm not :)
     
  6. Pendrush

    Pendrush Well-Known Member Licensed User

    Code:
    If File.ExternalWritable = True Then
        
    SQL.Initialize(File.DirDefaultExternal, "mydb.db"True)
    Else     
        
    SQL.Initialize(File.DirInternal, "mydb.db"True)
    End If
     
  7. Pendrush

    Pendrush Well-Known Member Licensed User

    Or you can use this code:
    Code:
    SQL.Initialize(DataBasePath, "mydb.db"True)

    Sub DataBasePath As String
       
    If File.ExternalWritable = True Then
         
    Return File.DirDefaultExternal  
       
    Else
         
    Return File.DirInternal
       
    End If
    End Sub
     
  8. wimpie3

    wimpie3 Active Member Licensed User

    This seems to have done the trick... can't I use DirInternal on all occasions and simply leave out the if/then/else?
     
  9. Pendrush

    Pendrush Well-Known Member Licensed User

    Check my post above your. Or always use DirInternal.
     
  10. wimpie3

    wimpie3 Active Member Licensed User

    THANKS A MILLION!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice