I am doing a refactoring of many projects and I want to group together all the methods that access the database into a DataLayer library (instead of each proyect having its own class that access the database)
This is the approach that I am doing right now
private static Database DB = null ;
private static EventLog LOG = null ;
public static void Initialize()
{
string logName;
if (LOG == null)
{
logName = "DataLayer";
LOG = new EventLog();
if (!EventLog.Exists(logName))
{
//can fail because lack of permissions or other errors
try
{
EventLog.CreateEventSource(logName, logName);
}
catch (Exception)
{
}
}
LOG.Source = logName;
}
if (DB == null)
{
DB = DatabaseFactory.CreateDatabase("Name");
}
}
public static DataSet GetInfoFromDB(String param1, bool automatic)
{
DataSet resp;
DbCommand dbCommand;
object[] pars;
resp = null;
dbCommand = null ;
try
{
//prepare the parameters
pars = new object[2];
pars[0] = param1;
pars[1] = automatic;
dbCommand = DB.GetStoredProcCommand("StoredProcedureName", pars);
dbCommand.CommandTimeout = 1200;
resp = DB.ExecuteDataSet(dbCommand);
}
catch (Exception ex)
{
LOG.WriteEntry(string.Format("Error al ejecutar el StoredProcedure \"GetInfoFromDB\" {0}", ex.Message), EventLogEntryType.Error, 2004);
}
finally
{
if (dbCommand!= null)
{
dbCommand.Dispose();
}
}
return resp;
}
What are the posible issues of using single static instance of the de EnterpriseLibrary Database class for a DataLayer library ?
By issues I mean leaked connections, or if one mehod can somehow affect the others when multiple process start calling those methods or anyother
I would usually solve this by trial an error but I want to have an answer based on concepts and techinical/official information
ADDED
The main goal of the DataLayer and the refactor that I am planning is to take all the DB utility/common methods like GetAllParameters and many others that are replicated over and over on each project to avoid having to mantain and test them in every single project.
What I want is a unique method GetAllParameters that is called/reused in all the other projects
Therefore all the Common methods that can be used by many projects and are not part of a certain bussiness logic will be placed in DataLayer.Common like DataLayer.Common.GetAllParameters
And each logic that is specific for certiain funcionality will go inside its own DataLayer.BusinessLogicA.GetSpecificInfo
Is important to mention that this DataLayer will be used from projects like this
Website-->WebService-->BusinessLogic-->Datalayer
Winservice-->Datalayer
Winform-->Datalayer