Reputation: 327
This is my function for selecting data from database:
public DataTable SelectDataTable(string selectStatement, string connectionString)
{
using (var oracleConnection = new OracleConnection(connectionString))
{
using (var command = new OracleCommand(selectStatement, oracleConnection))
{
return SelectDataTable(command);
}
}
}
public DataTable SelectDataTable(OracleCommand command)
{
var result = new DataTable();
try
{
var adapter = new OracleDataAdapter(command);
adapter.Fill(result);
} catch (OracleException ex)
{
throw NewDatabaseException("Error on fill data table.", command.CommandText, ex);
}
return result;
}
I call this function very often and I am little afraid that there can be performance issue because I am still creating new DbConnection. Is it better to crete only one DbConnection, store it in field and use it multiplt time?
Upvotes: 1
Views: 217
Reputation: 3319
Set MinPoolSize to value greater than 0 in your connection string, so instead of creating new connections, it will be taken from the pool of existing connections. Also set MaxPoolSize at number higher than MinPoolSize.
Upvotes: 1