using Singleton to control database access
Posted by: Chris Bassett
Date: October 29, 2014 03:47PM

I have a Windows app that I'm writing (desktop application) that has several objects (it's being written in C#), and each object needs to access the database somewhow to both read and write data.

What I'm wondering is if I should have a common database object that is accessed by each object, so that there is (technically) only one database connection per client machine (or at least, per instance of the program being run), or should I Have a separate database connection object for each object within the program (Object meaning that I'm writing an add-on for an accounting system, so my objects would be things like SAles Order, Shipment, Serial Number, etc).

I thought about using the Singleton pattern in each of the objects to control database access connections, but the problem is that there are cases where I may need to create a few instances of a particular object/class, but I only want one instance to be able to access the database at a time, and ideally, one connection among all objects in existance, regardless of what type they are (Sales ORder, Serial Number, Shipment, etc).

Suggestions?

Options: ReplyQuote


Subject
Written By
Posted
using Singleton to control database access
October 29, 2014 03:47PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.