cancel
Showing results for 
Search instead for 
Did you mean: 

Close user connection or Logout ?

Former Member
0 Kudos

Hi,

I am using connection pool by enabling AutoPooling=True in the config settings of .NET client application.

How can I ensure that when the user logout from the .NET client application, all the connection are removed/Closed for that user ?

I can see in SM04 that USER ID remains there even if the user has logout from the system.

Please help!

Regards.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Jitesh,

How are you today ?

I have put a code example of a web service invoking a rfc.

please check it's connection usage, it should help out.

with respect,

amit

Former Member
0 Kudos

Hi Jitesh,

How are you doing ?

The connection pooling keeps the connection active

connection.dispose is a property of the connection, not of the connection pool

please ensure you return the connection to the connection pool

as you have auto pooling enabled, that will take care of the connection.

if the user is remaining active, then your connection is not only active, it is also OPEN.

the .net application does not maintain an open connection on the SAP system.

the user is logged in only for the time of the call of the rfc.

you will need to

1> explicitly close the connection

2> return the connection to the connection pool

as per

http://help.sap.com/saphelp_nw2004s/helpdata/en/14/1333021b8cae4e90c65dffff9e303f/content.htm

the 'dispose' method is defined, but it's functionality is not explicitly defined

also are you getting the connection from the pool ?

when you create a new connection, you first need to check in the pool if it exists, otherwise create a new one, and then return it to the pool.

the pool does a hash key search for the connection on the 'connection string' parameter.

with respect,

amit

Former Member
0 Kudos

Hi Amit,

Thanks for your reply but that's what I wish to acheive as you suggested-

1> explicitly close the connection ? How?

What I observed it that if the Autopooling is set to TRUE, no matter whether I call Close() or Dispose() or ReturnConnection(), I can still see the USER ID logged on through SM04?

And strange is that it's not the case everytime. Sometimes the USERIDs gets disapperead right away.

Thats why I am looking for some way to explicitly close the connection/remove from pool once the users logout from the .NET application.

Former Member
0 Kudos

Hi Jitesh,

the expected behaviour is for the user to dissappear immediately. so if you got that, check the code for those calls, it is correct.

the user should be logged in only as long as the connection is OPEN.

to explicitly close the connection.

if (con2SAP.IsOpen)

{

// close connection if open

con2SAP.Close();

}

// always return to pool once closed

myConnector.conReturnConnection(con2SAP);

}

public void conReturnConnection(SAP.Connector.Connection con2Return)

{

if(con2Return !=null)

{

con2Return.PrepareForPooling();

SAP.Connector.SAPConnectionPool.ReturnConnection(con2Return);

con2Return = null;

}

}

to get the connection from the pool :

public SAP.Connector.Connection conEstablishConnection(string strConnection)

{

SAP.Connector.Connection conReturn;

conReturn = null;

if(strConnection.Trim() !="")

{

conReturn = SAP.Connector.SAPConnectionPool.GetConnectionFromPool(strConnection);

}

return conReturn;

}

if the user is still logged in, it is due to the non closure of the connection.

with respect,

amit

Former Member
0 Kudos

Hi Jitesh,

How are you doing ?

Could you please let me know how you are using the connection a bit more ?

When using a .NET application, the connection is only opened when the BAPI / RFC call is made. Regardless if the call was successful or not.

So if your user is still logged in , it would mean the connection is still open.

In the 'finally' section [try catch, finally], check if the connection is still open and then explicitly close it. once closed it needs to be returned to the pool

when these measures are taken care of when calling the bapi / rfc's, reguardless of when the user closes the browser, the user is only active for the length of the bapi / rfc call.

Hence eliminating the scenario of having a user still logged in (SM04).

with respect,

amit

try

{

}

catch

{

}

finally

{

if (con2SAP.IsOpen)

{

// close connection

con2SAP.Close();

}

// return to pool

myConnector.conReturnConnection(con2SAP);

}

public SAP.Connector.Connection conEstablishConnection(string strConnection)

{

SAP.Connector.Connection conReturn;

conReturn = null;

if(strConnection.Trim() !="")

{

conReturn = SAP.Connector.SAPConnectionPool.GetConnectionFromPool(strConnection);

}

return conReturn;

}

public void conReturnConnection(SAP.Connector.Connection con2Return)

{

if(con2Return !=null)

{

con2Return.PrepareForPooling();

SAP.Connector.SAPConnectionPool.ReturnConnection(con2Return);

con2Return = null;

}

}

Message was edited by:

Amit Chawathe

Former Member
0 Kudos

Hi Amit,

I am invoking RFCs from .NET web based application using .NET connector. And here is how I am doing it:

1.In the web.config of .Net Application-

<SAP>

<Connector>

<ConnectionPool UseAutoPooling="TRUE" />

</Connector>

</SAP>

2. Creating conection-

'oSAPProxy is RFC proxy object

oSAPProxy.Connection = SAP.Connector.Connection.GetConnection(DestinationStrings.Item(Destination) & " USER=" & UserID & " passwd=" & Password & " LANG=EN")

3. Returning connection to pool-

Try

oSAPProxy.connection.dispose()

Catch

Finally

oSAPProxy = Nothing

End Try

The pool is working fine. The problem is SM04 still shows the userIDs who have logout from the .NET system. Which seems correct because the connection pool is managed by .NET Connector and so as the lifetime of the connection.

Is there a way I can force a particular user connection to be closed when user logout from .NET application? Thus removing connection from the pool.

I tried various methods but till now what I observed is, if the connection pool is ON then it's not letting me close the connection

Thanks for the help.