Hi I generate Dao classes for some DB operations
in this manner making methods of Dao class as static or none static is better?
Using sample dao class below ,İf more than one client got to use the AddSampleItem method in same time?how this may result?
public class SampleDao
{
static DataAcessor dataAcessor
public static void AddSampleItem(object[] params)
{
dataAcessor =new DataAcessor();
//generate query here
string query="..."
dataAcessor.ExecuteQery(query);
dataAcessor.Close();
}
public static void UpdateSampleItem(object[] params)
{
dataAcessor =new DataAcessor();
//generate query here
string query="..."
dataAcessor.ExecuteQery(query);
dataAcessor.Close();
}
}
It would result in a big mess. If you are adding 2 items simultaneously from different threads, you would certainly end up with very strange results, or even errors if one thread closes the
DataAcessorbefore the other completes.I would use a local
DataAcessoror create a new and use that in all the methods depending on how you want to manage the lifetime ofDataAcessor.