title: How to control SQLite in memory DB consumption using C# vb.net
body: <p><strong>I have 100 GB data. I want to load it in-memory using SQLite in VB.Net.  I have 32 GB RAM. I want SQLite to take 24 GB RAM and other 8 GB will remain free for other OS tasks. When it hits the 24 GB RAM limit It should start flushing data to some disk file automatically.</strong></p>
  
  <p>First: I used in-memory DB. </p>
  
  <pre><code>Dim cn As SQLiteConnection = New SQLiteConnection("Data Source=:memory:")
  </code></pre>
  
  <p>But it consumes 31.8 GB RAM, and then OS (Windows 7) jump in and takes the control and start using virtual memory (which saves data to disk). But it really really slows down the Computer. In short when to load huge data (by using in-memory method), SQLite eats up all ram and halts the computer.</p>
  
  <p>Second: I loaded the data using temporary DB.</p>
  
  <pre><code>Dim cn As SQLiteConnection = New SQLiteConnection("FullUri=file:")
  </code></pre>
  
  <p>But when SQLite consumed near 2GB RAM it frees it by flushing data to file “C:\Users\Administrator\AppData\Local\Temp\etilqs_d4Fsx23dc” and start loading next data. In short when to load huge data (by using temporary DB method), it uses very less RAM and More Disk.</p>
  
  <p>First scenario eats all ram and second consumes very less RAM. I need middle way that should be in my own control etc. 24 GB RAM for SQLite and 8 GB for OS, when it hits the 24 GB RAM limit, It should start flushing data to disk file automatically.</p>