A
Ahmet AKGUN
Hi;
I am trying to make a server that handles db connection pool.
Clients use TcpChannel to make a call to this server and get one
database connection (OleDbConnection) from pool.
But when I try to connect to server using TcpChannel,
I get this message "Only one usage of each socket address (protocol/network
adress /port)"
is normally permitted.
But then my call to GetDbConnFromPool succees and I get connection from
server.
Why I get the message above ?
Below you can see my server and client codes
Server code
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Data.OleDb;
using System.Windows.Forms;
namespace PoolManager
{
public class PoolServer : MarshalByRefObject
{
private int iConnCnt;
public PoolServer()
{
try
{
TcpChannel channel = new TcpChannel(5000);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(PoolServer),
"MilenasDbPool",
WellKnownObjectMode.Singleton
);
}
catch(System.Exception eSysExc)
{
MessageBox.Show(eSysExc.Message);
}
}
public OleDbConnection NewConnFromPool()
{
iConnCnt++;
OleDbConnection dbNewConn;
dbNewConn = new OleDbConnection("Provider=MSDAORA.1;Password=pwd;User
ID=usr;Data Source=DATABASE;Pooling=true");
return dbNewConn;
}
public void DisposeConn(OleDbConnection dbConn)
{
dbConn.Dispose();
iConnCnt--;
}
}
}
////////////////////////////////////////////////////////////////////////////
///////////////////////
////////////////////////////////////////////////////////////////////////////
///////////////////////
My Client Code is Below
public class PoolClient
{
public PoolClient(string host,string port)
{
try
{
string strDest = "tcp://" + host + ":" + port + "/MilenasDbPool";
TcpChannel chn = new TcpChannel();
ChannelServices.RegisterChannel(chn);
PoolServer plMan = (PoolServer)Activator.GetObject(
typeof(PoolServer),strDest);
OleDbConnection refConnFromPool = plMan.NewConnFromPool();
MessageBox.Show(refConnFromPool.ConnectionString);
refConnFromPool.Open();
}
catch(System.Exception eSysExc)
{
MessageBox.Show(eSysExc.Message);
}
}
}
Helps will be appreciated..
Ahmet.
I am trying to make a server that handles db connection pool.
Clients use TcpChannel to make a call to this server and get one
database connection (OleDbConnection) from pool.
But when I try to connect to server using TcpChannel,
I get this message "Only one usage of each socket address (protocol/network
adress /port)"
is normally permitted.
But then my call to GetDbConnFromPool succees and I get connection from
server.
Why I get the message above ?
Below you can see my server and client codes
Server code
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Data.OleDb;
using System.Windows.Forms;
namespace PoolManager
{
public class PoolServer : MarshalByRefObject
{
private int iConnCnt;
public PoolServer()
{
try
{
TcpChannel channel = new TcpChannel(5000);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(PoolServer),
"MilenasDbPool",
WellKnownObjectMode.Singleton
);
}
catch(System.Exception eSysExc)
{
MessageBox.Show(eSysExc.Message);
}
}
public OleDbConnection NewConnFromPool()
{
iConnCnt++;
OleDbConnection dbNewConn;
dbNewConn = new OleDbConnection("Provider=MSDAORA.1;Password=pwd;User
ID=usr;Data Source=DATABASE;Pooling=true");
return dbNewConn;
}
public void DisposeConn(OleDbConnection dbConn)
{
dbConn.Dispose();
iConnCnt--;
}
}
}
////////////////////////////////////////////////////////////////////////////
///////////////////////
////////////////////////////////////////////////////////////////////////////
///////////////////////
My Client Code is Below
public class PoolClient
{
public PoolClient(string host,string port)
{
try
{
string strDest = "tcp://" + host + ":" + port + "/MilenasDbPool";
TcpChannel chn = new TcpChannel();
ChannelServices.RegisterChannel(chn);
PoolServer plMan = (PoolServer)Activator.GetObject(
typeof(PoolServer),strDest);
OleDbConnection refConnFromPool = plMan.NewConnFromPool();
MessageBox.Show(refConnFromPool.ConnectionString);
refConnFromPool.Open();
}
catch(System.Exception eSysExc)
{
MessageBox.Show(eSysExc.Message);
}
}
}
Helps will be appreciated..
Ahmet.