Re: SQL Compact Edition - connection and multi-trheading



It sounds like your plan could work, but you'd want to serialize access to your singleton in a multi-threaded scenario. Also you'll need to make sure that the connections are all closed eventually. As long as each thread has its own connection, I don't see other issues immediately.

--
Ginny


"José Joye" <Me@xxxxxx> wrote in message news:465e6ae0$0$3809$5402220f@xxxxxxxxxxxxxxxxxx
This question relates to another one I posted. However it derives from the original post and found better to start a new one.

I'm writting a library application that will be used internally within our company (dB is used in RO mode). I already expect it to be used by multithreaded applications.
Having that in mind, I naively designed it with connection pooling in mind ( --> get a connection, use it and release it as soon as possible [kind of single call pattern]).
However, the connection pool is not supported by the SQLServer CE 3.1 and this means every time I'm asking for a connection object I have to wait about 2ms on my desktop and I expect to be much more on the CF devices

The question I have is related to connection together with multithreading.
In fact, to overcome the speed problem I have, I'm planning to write a kind of "DataObjectProvider singleton Class" that will hold a set of already initialized "db onnection".
Whenever needed, clients of this class may ask for an available connection and when they are done, they can replace it in the pool.

1. Assuming, my code ensures the connections are really given back to the singleton class when not needed anymore. Is this design valid?
2. Does it cause problem if different threads will query for connections (which were created by a different thread)?
3. Assuming I keep the connection open, when I place them back to the pool, will it make problem when used in multithreaded environment.

Thanks,
- José



.



Relevant Pages

  • RE: Disposing in a sealed class
    ... On a side note I don't see any reason to even have the Database class ... A singleton class could be useful for creating and maintaining a single ... managed by ADO.Net provided the connection string does not change from the ... to the calling object so that the calling object can continue with its ...
    (microsoft.public.dotnet.general)
  • Re: Keeping a database connection with a Singleton?
    ... an unpythonic pattern and all. ... Singleton anyways, so I just glanced over the document. ... the main-app has an open connection to the database. ... What's the cleanest way to hand this connection to the new window? ...
    (comp.lang.python)
  • Re: Singleton
    ... > going to be using a O/R mapping tool. ... > one instance to a database connection). ... The real problem with singletons is that singleton objects make singleton ...
    (comp.object)
  • Re: Singleton Pattern - practical alternatives?
    ... A singleton is a bad choice when you may ever want to dynamically ... opens one connection, various classes use this to perform SQL ... class Mainform extends JFrame { ... BarClass b = new BarClass; ...
    (comp.lang.java.programmer)
  • Re: Global Functions
    ... "Try to avoid a module, static class, singleton, shared class or whatever ... Dim ConnL3Producer As New OleDbConnection ... because each one opens a new connection. ... Private mConnection As OleDBConnection ...
    (microsoft.public.dotnet.languages.vb)

Loading