Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It helps to remember that both connection pooling and prepared (compiled) statements are just tools that have their limits and no approach can be equally suitable to all possible situations. With this in mind, let's remember when one might want to use connection pooling and prepared statements.</p> <p><strong>Possible Reasons to Use Connection Pooling</strong></p> <p>Connection pooling is useful when connections are expensive, for example:</p> <ul> <li>It takes <em>significant time</em> to establish a connection (network connections to a SQL Server or Oracle DB) and it is beneficial to "cache" open connections in an attempt to improve system performance.</li> <li>Connections are <em>limited and shared</em> within an application (connections from a web application serving multiple concurrent requests) or between applications so they have to be released as soon as possible to let the other clients continue.</li> </ul> <p><strong>Possible Reasons to Use Prepared Statements</strong></p> <p>Prepared statements are simply meant to improve performance of re-usable queries by cutting down the parsing time.</p> <p><strong>SQLite: What's the Best Choice?</strong></p> <p>The answer depends on your application requirements. Personally, I'm not sure if SQLite connection pooling is necessarily a good choice. If your application is single-threaded, it might be best to use a single permanent connection to the SQLite DB, which could be much faster than pooling and would allow you to use prepared statements too. This is different from SQL Server where connection pooling is a very reasonable default.</p> <p>If performance matters, you should definitely profile the application to see if the SQLite connection pooling is beneficial for your scenario.</p> <p><strong>Specific Questions</strong></p> <p>Most of the answers are related to the current <code>System.Data.SQLite</code> provider <a href="http://system.data.sqlite.org/index.html/dir?ci=trunk" rel="noreferrer">source</a>.</p> <blockquote> <p>If I am opening and closing my connection (which may or may not mean the connection is being closed due to the thread pool) then how much use am I really getting from a prepared statement?</p> </blockquote> <p>Generally, you should treat a connection coming out of the pool as new, i.e. you should not expect to get any benefit from statements prepared previously. The statement will be "re-prepared" unless you keep both the command and connection.</p> <blockquote> <p>However I don't believe I would see a benefit from saving a single object in a transaction because once I close the connection the prepared statement that was generated from the first object is now lost. Is this a true statement?</p> </blockquote> <p>This is a true statement.</p> <blockquote> <p>If I create a SQLiteCommand that represents a query that I will be executing often do I need to keep that SQLiteCommand in memory for the prepared statement to stay active?</p> </blockquote> <p>Yes, you need to keep it. <code>SQLiteCommand</code> holds a reference to the prepared statement.</p> <blockquote> <p>If I create a new SQLiteCommand with the same SQLite statement is it recognized that the new SQLiteCommand is the same as the previous and thus has a prepared statement that can be used?</p> </blockquote> <p>I don't think it's supported.</p> <blockquote> <p>If I keep a SQLiteCommand in memory and change it's parameters and connection as I open and close the connection for different transactions am I essentially keeping a prepared statement alive between different connections?</p> </blockquote> <p>If you change the <code>SQLiteCommand</code>'s connection, the statement will be "re-prepared".</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload