M
maxxx
I'm using SQL server and the Enterprise Library Data Access
Application Block using C# in a multi-tier environment.
I understand I need to have connections closed so that the connection
pool can reuse them - but my question is:
Should I (or should I not) keep a reference to the Database object
returned from the DatabaseFactory.CreateDatabase() method?
My database classes are static, and my intention was to have a private
static variable of type
Microsoft.Practices.EnterpriseLibrary.Data.Database, with a static
property which instantiates the Database object when needed.
private static Database _database;
private static Database DB
{
Get
{
If (_database == null)
{
_database = DatabaseFactory.reateDatabase("myconnection");
}
Return _database;
}
}
This would, I thought, improve performance as the object does not need
to be instantiated each time it is used.
What I do not know, though, is if the Database object needs to be
destroyed in order for it to close its connection, or if the
connection will be closed regardless (e.g. after closing a datareader
or getting a dataset).
So,,, is my idea a good one or a bad one- and importantly why?
Thanks for any advice.
..\\axxx
Application Block using C# in a multi-tier environment.
I understand I need to have connections closed so that the connection
pool can reuse them - but my question is:
Should I (or should I not) keep a reference to the Database object
returned from the DatabaseFactory.CreateDatabase() method?
My database classes are static, and my intention was to have a private
static variable of type
Microsoft.Practices.EnterpriseLibrary.Data.Database, with a static
property which instantiates the Database object when needed.
private static Database _database;
private static Database DB
{
Get
{
If (_database == null)
{
_database = DatabaseFactory.reateDatabase("myconnection");
}
Return _database;
}
}
This would, I thought, improve performance as the object does not need
to be instantiated each time it is used.
What I do not know, though, is if the Database object needs to be
destroyed in order for it to close its connection, or if the
connection will be closed regardless (e.g. after closing a datareader
or getting a dataset).
So,,, is my idea a good one or a bad one- and importantly why?
Thanks for any advice.
..\\axxx