Cache Database Object Best Practice [DAAB]

Topics: Data Access Application Block
Apr 21, 2010 at 3: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
{
  get
  {
    if (CACHED_DATABASE == null)
    {
      CACHED_DATABASE = DatabaseFactory.CreateDatabase(Settings.ConnectionStringName);
    }
    return CACHED_DATABASE;
  }
}

 

 

 

 

 

 

 

 

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

 

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

 

</font>

 

Apr 21, 2010 at 6: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.