Database Routines
-
Hi Guys, I always get stuck into thinking about the best way / most correct way of coding something. I'm writting an application which uses a databasse. One of table is used to store configuration information used (as example) by the configuration class/object. Now at the moment, my database code including it's creation is all contained within a static class named Database. My questions are: 1) Is having a static class for database routines a good idea? There is a potential for the application to be multi-threaded although each thread would most likely access different tables from the database. 2) Where is it best to code the rotine to load the configuration from the database? I could have a method like Database.LoadConfig( Config config ) where an singleton instance of Config is passed to the Database --or-- I could have a method in the Config Class like Config.Load(). Any thoughts and comments appreciated.
Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students View my Blog
-
Hi Guys, I always get stuck into thinking about the best way / most correct way of coding something. I'm writting an application which uses a databasse. One of table is used to store configuration information used (as example) by the configuration class/object. Now at the moment, my database code including it's creation is all contained within a static class named Database. My questions are: 1) Is having a static class for database routines a good idea? There is a potential for the application to be multi-threaded although each thread would most likely access different tables from the database. 2) Where is it best to code the rotine to load the configuration from the database? I could have a method like Database.LoadConfig( Config config ) where an singleton instance of Config is passed to the Database --or-- I could have a method in the Config Class like Config.Load(). Any thoughts and comments appreciated.
Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students View my Blog
Wayne Phipps wrote:
- Is having a static class for database routines a good idea?
If you don't have too much interation with the database its fine. For larger applications you may wish to split up the interation into more logical divisions (maybe with a common base class)
Wayne Phipps wrote:
There is a potential for the application to be multi-threaded although each thread would most likely access different tables from the database.
There are two ways I normally deal with a DAL. One is with the Enterprise Libraries. And the other is to do my own thing and for that the only shared information is a connection string that doesn't change. Each request to the database uses its own connection object (which is regarded as best practice) so there is no threading problems. If multiple things are accessing the database the database will handle it.
Wayne Phipps wrote:
- Where is it best to code the rotine to load the configuration from the database?
I typically have a configuration class (a singleton class) that loads the information from the config file. All other code in the application can then access it. If the configuration is large and complex I'll probably have a number of config classes to handle the various subsystems of the application. (Again, each will be a singleton - as all this is coming from a database, you may consider a common base for each of these an advantage)
Upcoming events: * Glasgow Geek Dinner (5th March) * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos
-
Wayne Phipps wrote:
- Is having a static class for database routines a good idea?
If you don't have too much interation with the database its fine. For larger applications you may wish to split up the interation into more logical divisions (maybe with a common base class)
Wayne Phipps wrote:
There is a potential for the application to be multi-threaded although each thread would most likely access different tables from the database.
There are two ways I normally deal with a DAL. One is with the Enterprise Libraries. And the other is to do my own thing and for that the only shared information is a connection string that doesn't change. Each request to the database uses its own connection object (which is regarded as best practice) so there is no threading problems. If multiple things are accessing the database the database will handle it.
Wayne Phipps wrote:
- Where is it best to code the rotine to load the configuration from the database?
I typically have a configuration class (a singleton class) that loads the information from the config file. All other code in the application can then access it. If the configuration is large and complex I'll probably have a number of config classes to handle the various subsystems of the application. (Again, each will be a singleton - as all this is coming from a database, you may consider a common base for each of these an advantage)
Upcoming events: * Glasgow Geek Dinner (5th March) * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos
It often helpfull to have another persons perspective on the situation. Many thanks for your comments. They were indeed helpfull
Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students View my Blog