I really want to the Database instance would be static

Topics: Data Access Application Block
Sep 16, 2011 at 8:39 AM

i'm eager to know there is any question if the Database instance as a static public.

code such as 

 

public Datahepler

{

private static Database db=null;

public static Database DB

{

if(db==null)

db=DatabaseFactory.CreateDatabase();

return db;

}

}

 

some class :

DbCommand cmd= DHHelp.DB.GetSqlCommand(string)

DBHelper.DB.AddParameter();

DBHelper.DB.ExecuteNonQuery(cmd);

Sep 18, 2011 at 5:53 PM

Hi,

I don't find any issue on that. Quoting from Christ Tavares on StackOverflow:

"You can (make database object static), but there's no significant reason to. Database instances are cheap to create and don't hold any state."

Hope this helps.

 

Noel Angelo Bolasoc
Avanade Software
Avanade, Inc.
Contact Us