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???)