I am trying to use Sqlite as a memory database with ServiceStack ORMlite in my unit tests.
If I run my tests with SQLite saving to a file, ie. using the connectionstring
"Data Source=|DataDirectory|unittest.db;Version=3;"
, it works fine and auth tables are generated fine by ServiceStacks
userRepository.CreateMissingTables();
However, when I try using SQLite as a memory database by using this connectionstring
":memory:"
I get an exception when saying
SQLite error
no such table: UserAuth
the first time I try to fetch a user by doing this
userRepository.GetUserAuthByUserName(...)
This is after I have called userRepository.CreateMissingTables() and it works fine if I switch to using SQLite with a file database. Does anybody know what the problem could be? (I had to down grade to version 3.9.0 of ORMLite because of bad references to version 1.0.65.0 of ORM lite in Ormlite 3.9.4)
ServiceStack v5
Recent versions of ServiceStack automatically disables
AutoDisposeConnectionfor SQLite:memory:connections, so you can configure yourOrmLiteConnectionFactorynormally, e.g:ServiceStack v3
You lose your database whenever you close the DB connection of an Sqlite in memory database.
So when you configure your DB Factory you need to tell it to never dispose of the connection, which you can do with the
autoDisposeConnectionconstructor param, e.g: