# Change inmemory db to file-based db

**URL:** <https://forum.xojo.com/t/change-inmemory-db-to-file-based-db/25201>\
**Category:** Databases\
**Created:** [June 28, 2015, 7:26pm UTC](https://forum.xojo.com/t/change-inmemory-db-to-file-based-db/25201 "2015-06-28T19:26:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Timo\_Ruohomaki](https://forum.xojo.com/user_avatar/forum.xojo.com/timo_ruohomaki/32/2264_2.png) [@Timo\_Ruohomaki](https://forum.xojo.com/u/Timo_Ruohomaki)\
**Post date:** [June 28, 2015, 7:26pm UTC](https://forum.xojo.com/t/change-inmemory-db-to-file-based-db/25201/1 "2015-06-28T19:26:40Z")

</div>

I was working on a data migration/cleansing app today. I use SQLiteDatabase as an inmemory db so that all the CSV imports and merges and cleansing would be done there. Finally, the user would have an option to export the db as a sqlite3 -file if required.

The strange thing is the following: I can create the inmemory db normally, insert databaserecords and do queries. I cannot however assign it with a folderitem using db.DatabaseFile = exportfolderitem and db.CreateDatabaseFile. If I do that of the database that is a global property, the result is an empty file with size of about 3 kB. I can still do queries on that object though and see that it has 21 columns and 21000 records.

I can of course forget the idea of using the db as inmemory db and instead of create always a file but the behaviour seemed strange. Why wouldn’t I be able to assign a file on database object later on?

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [June 28, 2015, 8:32pm UTC](https://forum.xojo.com/t/change-inmemory-db-to-file-based-db/25201/2 "2015-06-28T20:32:18Z")

</div>

are you attempting to change from In-Memory to filebase WHILE the database connection is active?  
That you cannot do… you must close the connection and reopen it.  
And doing so does NOT automatically transition the data from one place to the other if that is what you are looking for. to do that you need TWO connections, or a file copy.

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [June 28, 2015, 8:38pm UTC](https://forum.xojo.com/t/change-inmemory-db-to-file-based-db/25201/3 "2015-06-28T20:38:44Z")

</div>

Have a look at this command [SQLiteDatabase.AttachDatabase](http://documentation.xojo.com/index.php/SQLiteDatabase.AttachDatabase).

---

<div class="post-metadata">

**Author:** ![Timo\_Ruohomaki](https://forum.xojo.com/user_avatar/forum.xojo.com/timo_ruohomaki/32/2264_2.png) [@Timo\_Ruohomaki](https://forum.xojo.com/u/Timo_Ruohomaki)\
**Post date:** [June 28, 2015, 9:22pm UTC](https://forum.xojo.com/t/change-inmemory-db-to-file-based-db/25201/4 "2015-06-28T21:22:58Z")

</div>

Thanks for these! The AttachDatabase is close but I understood it would require the file actually existing and being a valid sqlite3 -file. So what I’d want to do is sort of other way round. The backup method actually would do the thing and would also allow versioning.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:49pm UTC](https://forum.xojo.com/t/change-inmemory-db-to-file-based-db/25201/5 "2020-10-29T17:49:31Z")

</div>


