0

I have the below 2 functions for reading data from existing SQLite DB and it works correct, but my questions is how can I read from the existing Protected SQLite DB with Password?

        private string GetSQLiteDBPath()
    {
        return Path.Combine(DB_PATH, DB_NAME);
    }
      public override SQLiteDatabase WritableDatabase
    {
        get
        {
            return CreateSQLiteDB();
        }
    }

    private SQLiteDatabase CreateSQLiteDB()
    {
        SQLiteDatabase sqliteDB = null;
        string path = GetSQLiteDBPath();
        Stream streamSQLite = null;
        FileStream streamWriter = null;
        Boolean isSQLiteInit = false;
        try
        {
            if (File.Exists(path))
                isSQLiteInit = true;
            else
            {
                streamSQLite = context.Resources.OpenRawResource(Resource.Raw.DBStore);
                streamWriter = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
                if (streamSQLite != null && streamWriter != null)
                {
                    if (CopySQLiteDB(streamSQLite, streamWriter))
                        isSQLiteInit = true;
                }
            }
            if (isSQLiteInit)
                sqliteDB = SQLiteDatabase.OpenDatabase(path, null, DatabaseOpenFlags.OpenReadonly);
        }
        catch { }
        return sqliteDB;
    }
  • I'm not entirely sure but have you looked at the SQLCipher component for Xamarin Android? There's some sample code on the Component's page that may be of interest to you. – MikeOscarEcho Nov 30 '16 at 22:04
  • Dear @MikeOscarEcho I just want to open db protected by password, I don't like to encrypt my db – Yousif Garabet Nov 30 '16 at 22:12
  • 3
    Possible duplicate of [Password Protect a SQLite DB. Is it possible?](http://stackoverflow.com/questions/1381264/password-protect-a-sqlite-db-is-it-possible) – jgoldberger - MSFT Dec 01 '16 at 01:19
  • 1
    What do you mean by password protected? Do you need password to open the DB? Then refer @jgoldberger 's comment above – Prashant Cholachagudda Dec 01 '16 at 05:24
  • Dear @jgoldberger I think it's a little bit different from my project check my code then if you can help me? my file.db3 is protected by a password so I couldn't open it!! but when I remove the password from my file.db3 then it works perfectly – Yousif Garabet Dec 01 '16 at 17:49

0 Answers0