Copy sqlite db into Android app

JamesHeaneyJamesHeaney James HeaneyGBMember
edited June 2013 in Xamarin.Android

Please help. I cannot get my sqlite DB to copy into my Android app. I have done this without issue for a iOS app but the android path seems sooo much harder!

I have the sqlite DB (eng.sqlite) in the root folder of my project. I have tried "Content" build actions (like in the iOS app), AndroidResource, AndroidAsset, EmbeddedResource but I still get "File not found" when i try to copy my DB into the "databases" folder.

I have also tried putting the db in the Assets folder and then tried every build option but still cannot find the file!

string db = "/data/data/SpecDroid.SpecDroid/databases/eng.sqlite"; 

string rootDbPath = "/data/data/SpecDroid.SpecDroid/eng.sqlite"; 

//rootDbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "eng.sqlite"); <-- DIDNT WORK

if(File.Exists(db) == false) {
    Console.WriteLine("Installing DB!");
File.Copy(rootDbPath, db);


Any ideas??

All i want to do is copy a previously built sqlite db into the databases folder and then connect to it.



  • JamesHeaneyJamesHeaney James Heaney GBMember

    Yep - he had the same problem too. No solution tho.

  • StevenTheEvenStevenTheEven Michael Andersson SEMember ✭✭✭

    Huh? Read more then one comment.

  • BenLuBenLu Ben Lu TWMember ✭✭

    Hi James,

  • BenLuBenLu Ben Lu TWMember ✭✭

    @JamesHeaney Hi James,
    Did you resolve this issue?
    In my project,just like you. I have a SQLite DB,I tried to use Path.GetFullPath to get path of my SQLite DB and "Content" build actions.But I can't do file.copy or did you find a solution to resolve this issue?

  • MannyDiazMannyDiaz Manny Diaz USMember

    I'm getting a access denied when I try to copy the sqlite database from the Assets to /data/data/Android.Android/files/

    `string DB_PATH = "/data/data/Android.Android/files/";
    string DB_NAME = "database";

        private void copyDataBase()
            using (var assets = Assets.Open(DB_NAME))
                using (var dest = File.Create (DB_PATH))
                    assets.CopyTo (dest);

    Any help would be appreciated.

  • JohnMurrayJohnMurray John Murray GBMember ✭✭
    edited November 2013

    Manny - see my thread 'newbie question' more recently
    In short - if you put the sqlite in the assets folder of the project you have to open it as astream and write it to the \data\com.myapp\files folder on your device
    this is some example code for 'copy2dtabase which workss for me.

    // copy database
                Stream iStream = Assets.Open("locair.db3");
                oStream = new FileOutputStream(outFilePath);
                byte[] buffer = new byte[2048];
                int length = 2048;
                //    length = Convert.ToInt16(length2);
                while (iStream.Read(buffer, 0, length) > 0)
                    oStream.Write(buffer, 0, length);
  • WilliamAndrewSowerbyWilliamAndrewSowerby William Andrew Sowerby GBMember

    I use the following code as suggested by Jonathan Prior:

    private void copyAssetDataBase()  
                using (var source = Assets.Open(@"app.db"))
                using (var dest = OpenFileOutput("app.db", FileCreationMode.WorldReadable | FileCreationMode.WorldWriteable))
  • rabih.7535rabih.7535 rabih USMember

    any update regarding the upload of sql lite db to a real android device?

  • WilliamAndrewSowerbyWilliamAndrewSowerby William Andrew Sowerby GBMember

    Well, we provide ADB push/pull and Wi-Fi file transfer options. The Wi-Fi option uses Apple's Bonjour for Windows with sockets on the PC and NSD Manager on the Android.

  • Abd.5493Abd.5493 Abdalhadi Suwwan USMember

    You can find what you want here

    but you need to add permissions for read and write from External storage

Sign In or Register to comment.