I am fetching my Database object in PetaPoco using this method:
internal static Database GetCurrentDatabase()
{
if (HttpContext.Current == null)
{
if (Thread.GetData(Thread.GetNamedDataSlot(_databaseKey)) != null)
return Thread.GetData(Thread.GetNamedDataSlot(_databaseKey)) as Database;
else
{
var database = new Database("testDB");
database.KeepConnectionAlive = true;
database.EnableAutoSelect = true;
database.CommandTimeout = 180;
Thread.SetData(Thread.GetNamedDataSlot(_databaseKey), database);
return database;
}
}
else
{
if (HttpContext.Current.Items.Contains(_databaseKey))
return HttpContext.Current.Items[_databaseKey] as Database;
else
{
Database database = new Database("testDB");
database.EnableAutoSelect = true;
database.CommandTimeout = 180;
database.KeepConnectionAlive = true;
HttpContext.Current.Items[_databaseKey] = database;
return database;
}
}
}
My connection string in web.config:
<add name="testDB" connectionString="Data Source=192.168.10.10;Initial Catalog=testDB;User Id=test;Password=test;pooling='true'; Max Pool Size=200"
providerName="System.Data.SqlClient" />
Question is already connection pooling is enabled. Do I have to set KeepConnectionAlive
as true or false? What is the use of this property?
Yes, pooling is already enable and you don't need to set KeepConnectionAlive to true (in fact, it will bring trouble if you set it to true)