|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Sharing connection between threadsHello,
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,
<kol***@yahoo.com> wrote in message news:1131111528.280489.196480@g44g2000cwa.googlegroups.com... Physical connection - yes.> 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 Can we see some code? When you close conneciton it is released back to pool.> 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. How do you know that it isn't? -- Miha Markic [MVP C#] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ 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? -- Show quoteMiha Markic [MVP C#] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ <kol***@yahoo.com> wrote in message news:1131366644.894113.77560@g43g2000cwa.googlegroups.com... > 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? > On 4 Nov 2005 05:38:48 -0800, kol***@yahoo.com 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. -- Show quote____________________________________ 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. __________________________________ <kol***@yahoo.com> wrote in message news:1131111528.280489.196480@g44g2000cwa.googlegroups.com... > 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- > |
|||||||||||||||||||||||