Remoting Using TcpChannel (Urgent)

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.
 
S

Scott C. Wagner

You're registering the remoting channel in the constructor of the object
that is being created. Therefore, you're attempting to register the
channel every time a client requests the object be created.

HTH,
Scott Wagner
Seisint, Inc.
 
A

Ahmet AKGUN

that solved the problem.
thanks.


Scott C. Wagner said:
You're registering the remoting channel in the constructor of the object
that is being created. Therefore, you're attempting to register the
channel every time a client requests the object be created.

HTH,
Scott Wagner
Seisint, Inc.


/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top