Cache Database Object Best Practice [DAAB]

Topics: Data Access Application Block
Apr 21, 2010 at 4:24 PM

Hi All

First time on this forum so thanks for any help and please excuse if this has been asked before.

Is it good practice to cache the database object when using the DAAB or doesn't it matter:

private static Database CACHED_DATABASE;

/// <summary>
/// Creates provider specific database
/// </summary>
private static Database Database
    if (CACHED_DATABASE == null)
      CACHED_DATABASE = DatabaseFactory.CreateDatabase(Settings.ConnectionStringName);









<font size="2" color="#0000ff"><font size="2" color="#0000ff">


</font></font><font size="2" color="#0000ff">




Apr 21, 2010 at 7:23 PM

No, don't do that. Database is a cheap wrapper, they're trivial to create and don't take much time. It's much, much easier to simply create when needed and throw it away when done.