I am using LocalDb in an integration testing environment - instantiating and disposing of my instance before and after my tests run.
However, when I create a database within my instance, it still flushes my tables and data to disk. Is it possible to run LocalDb in an "in-memory" mode? And if so how?
LocalDB is absolutely supported in production. From the performance point of view it is identical to SQL Server Express, as they share the same database engine. Now, for a site running in full IIS I would recommend using service-based instance of SQL Server Express.
The system database files for the database are stored in the local AppData path, which is normally hidden. For example, C:\Users\<user>\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\LocalDBApp1\ .
This database provider allows Entity Framework Core to be used with an in-memory database. While some users use the in-memory database for testing, this is generally discouraged; the SQLite provider in in-memory mode is a more appropriate test replacement for relational databases.
LocalDB is a lightweight version of the SQL Server Express Database Engine that is targeted for program development. LocalDB starts on demand and runs in user mode, so there is no complex configuration. SQL Server is the Microsoft-driven relational database management system.
You could run your tests against a database in a RAM disk. I have done that a while ago and it seemed to improve integration tests performance by a factor of 2 or 3! This was on a Windows 7 VM hosted in a MacBook Pro with an SSD. Your milage will probably be better if you have a mechanical HDD.
Since SQL Server allows you to specify the mdf file in a connection string via "AttachDbFileName=", you can leverage that by pointing to an mdf in a RAM disk.
The RAM disk device driver I used was ImDisk, which is available for both 64 and 32 bit Windows. Linux counterparts are numerous.
No. LocalDB is still SQL Server, and in SQL Server there is no concept of an in-memory database. All databases are disk-backed, with in-memory cache sitting on top of them.
You could probably write a custom step in your testing harness to drop your databases after your tests are completed and delete database files. Maybe even it's already there if you're using TFS for build and test runs? But there's nothing in LocalDB to make it automatic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With