Can I run LocalDb "in-memory"

I use LocalDb in an integration testing environment - instantiating my instance and deleting it before and after running my tests.

However, when I create the database in my instance, it still flushes my tables and data to disk. Is it possible to run LocalDb in "in-memory" mode? And if so, how?

+5
source share
2 answers

Not. LocalDB is still SQL Server, and SQL Server does not have a database concept in memory. All databases are protected against copying to disk, while they contain a memory cache.

You could probably write a special step in your testing to drop your databases after completing the tests and delete the database files. Maybe even it already exists if you use TFS for assembly and testing? But there is nothing in LocalDB to make it automatic.

+2
source

You can run your tests against a database on a RAM disk. I did this a while ago, and it seems to improve the performance of integration tests by 2 or 3 times! This was on a Windows 7 virtual machine hosted on a MacBook Pro with an SSD. Most likely, your weapons will be better if you have a mechanical hard drive.

Since SQL Server allows you to specify the mdf file in the connection string via "AttachDbFileName =", you can use this by pointing to the mdf in the RAM disk.

The RAM device driver that I used was ImDisk, which is available for both 64 and 32-bit Windows. Compatible with Linux.

+4
source

All Articles