Sharing connection between threads

  • Thread starter Thread starter koltti
  • Start date Start date
K

koltti

Hello,

Is it possibility to share connections between threads using ado.net
pooling system?

I'm using remoting and I want that clients can share connection by
using ado.net pooling system. It seem that thread will not release
connection to pool when connection is closed(Close() method called) or
then other thread created by remoting system will not accept that
connection from pool.

-koltti-
 
Hi,

Hello,

Is it possibility to share connections between threads using ado.net
pooling system?

Physical connection - yes.
I'm using remoting and I want that clients can share connection by
using ado.net pooling system. It seem that thread will not release
connection to pool when connection is closed(Close() method called) or
then other thread created by remoting system will not accept that
connection from pool.

Can we see some code? When you close conneciton it is released back to pool.
How do you know that it isn't?
 
On 4 Nov 2005 05:38:48 -0800, (e-mail address removed) wrote:

¤ Hello,
¤
¤ Is it possibility to share connections between threads using ado.net
¤ pooling system?
¤
¤ I'm using remoting and I want that clients can share connection by
¤ using ado.net pooling system. It seem that thread will not release
¤ connection to pool when connection is closed(Close() method called) or
¤ then other thread created by remoting system will not accept that
¤ connection from pool.

I'm not sure if I understand your configuration but connection pooling is established per process
and per unique connection string (including credentials). If there is no existing connection pool,
for the process, connection string and credentials requesting a connection, a new connection pool
will be created.

If you are using a native .NET provider, connection pooling can be established amongst processes in
the same application pool (based upon the previously specified conditions).


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Connections are not "sharable" unless you serialize the operations--they can
only run one operation at a time. If you use ADO.NET 2.0 you can use MARS to
reuse a connection, but there are a number of other restrictions there as
well. Connections should be closed and reopened (against the pool) for best
operations.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Hi,

Here I have sample code for this situation.
Server:

class CServer{
[STAThread]
static void Main(string[] args){
TcpServerChannel channel = new TcpServerChannel(8099);
ChannelServices.RegisterChannel(channel);

RemotingConfiguration.RegisterWellKnownServiceType(
typeof(DBTest.CDBTest), "DBTest",
WellKnownObjectMode.Singleton);

Console.WriteLine("Remote Server Ready on Port: {0} ...", 8099);
Console.WriteLine("Press any key to exit ...");
Console.ReadLine();
}
Class which will be instantiate by client:

public class CDBTest: MarshalByRefObject{
OracleConnection conn;
public void open(){
conn = new OracleConnection("Password=xxx;User ID=xxx;Data
Source=xxxx");
conn.Open();
}
public void close(){
conn.Close();
}
}
Client:

class CClient{
[STAThread]
static void Main(string[] args){
TcpClientChannel channel = new TcpClientChannel();
ChannelServices.RegisterChannel(channel);

DBTest.CDBTest dbTest =
(DBTest.CDBTest)Activator.GetObject(typeof(DBTest.CDBTest),"tcp://localhost:8099/DBTest");
dbTest.open();
Console.WriteLine("Press any key to close connection ...");
Console.ReadLine();
dbTest.close();
Console.WriteLine("Press any key to exit ...");
Console.ReadLine();
}
}

I tried like this.
1. Start server (after that no open connection to database)
2. Start first client, do NOT hit the key to close connection (after
that 1 open connection to database)
3. Start second client (after that 2 open connections to database)
4. Close first and second clients (after that 2 open connections to
database, because connections are released to pool)
5. Start third client, do NOT hit the key to close connection (after
that 2 open connections to database, because connection for third
client is got from pool)
6. Start fourth client (3 open connections to database!!!, why
connection is not got from pool???)
 
Damn, of course it works like that since I use Singleton and Server
Activation (First connection created for first client will never
release).
Maybe I have to use Client Activation in case like this?
 
Perhaps you could use SingleCall and do open and close both in that call -
it will be even safer to do it in this way?
 
Back
Top