ServiceStack OrmLite using Sqlite64 as the database database results in the absence of auth tables

I am trying to use Sqlite as a memory database with ServiceStack ORMlite in my unit tests.

If I run my tests while saving SQLite to a file, i.e. using a connection string

"Data Source=|DataDirectory|unittest.db;Version=3;" 

it works fine and authentication tables are generated perfectly with ServiceStacks

 userRepository.CreateMissingTables(); 

However, when I try to use SQLite as a memory database using this connectionstring

 ":memory:" 

I get an exception by saying

 SQLite error no such table: UserAuth 

the first time I try to extract a user by doing this

 userRepository.GetUserAuthByUserName(...) 

This is after I called userRepository.CreateMissingTables (), and it works fine if I switch to using SQLite with a file database. Does anyone know what the problem is? (I had to downgrade the class to version 3.9.0 from ORMLite due to poor references to version 1.0.65.0 of ORM lite in Ormlite 3.9.4)

+4
source share
1 answer

ServiceStack v5

Recent versions of ServiceStack automatically disable AutoDisposeConnection for SQLite :memory: connections, so you can configure your OrmLiteConnectionFactory as a rule, for example:

 var dbFactory = new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider); var sqliteRepo = new OrmLiteAuthRepository(dbFactory); sqliteRepo.CreateMissingTables(); 

ServiceStack v3

You lose your database whenever you close the Sqlite DB database connection in memory.

Therefore, when you set up your DB Factory, you need to tell it to never remove the connection that you can make with the AutoDisposeConnection constructor AutoDisposeConnection , for example:

 var dbFactory = new OrmLiteConnectionFactory(":memory:", autoDisposeConnection:false, dialectProvider:SqliteDialect.Provider); var sqliteRepo = new OrmLiteAuthRepository(dbFactory); sqliteRepo.CreateMissingTables(); 
+4
source

All Articles