Skip to Content

SAPConnection Pooling and Web Services

Hi,

We have build a lot of .NET web services which are connecting to various SAP systems (depending on the front-end user).

To improve performance we were considering using the SAPConnectionPool class ...

We have some questions about this class:

1) While thinking about it we were wondering if there is actually any benefit considering the stateless nature of web services ...

How would we actually manage that the connection pool remains in place for each subsequent web service call (so the pool does not need to restart over and over again, obviously loosing its benefits) ...

Would it work by add methods to the Global class?

2) To get at least one open connection available to each SAP system before the first web service is called, would it be sufficient to just ask for a connection to each system and immediately return it again to the pool (this would then be executed in the global class )

Perhaps we are missing some fundamental stuff here but be patient with us ... we are only working for 6 months in the .NET environment (coding like hell in C# 😊 )

Thx,

Steven

-


Here is the code we added to the global.asax:

public static void InitializeSAPConnectionPooling()

{

// Try to get the SAP connections from the application memory

Hashtable wSAPConnections = (HashtableHttpContext.Current.Application["SAPConnections"];

// When we have it

if ( wSAPConnections != null )

{

// For each connection, start up a connection in the pool

foreach( DictionaryEntry wElement in wSAPConnections )

{

// Get a connection

SAPConnection wConnection = SAPConnectionPool.GetConnection((string)wElement.Value);

// Return the connection back to the pool SAPConnectionPool.ReturnConnection(wConnection);

}

}

}

Add comment
10|10000 characters needed characters exceeded

2 Answers

  • Posted on Jul 06, 2004 at 12:19 PM

    Let me shortly explain when Connection Pool is usefull and how it works:

    Connection Pool makes sense, if you have many subsequent calls with the same connection string,e.g.

    string connectionString = "...";

    ...

    SAPProxy1 proxy = new SAPProxy1();

    ...

    proxy.Connection = SAPConnectionPool.GetConnection(connectionString);

    proxy.CallMethod();

    SAPConnectionPool.ReturnConnection(proxy.Connection);

    ...

    proxy.Connection = SAPConnectionPool.GetConnection(connectionString);

    proxy.CallMethod();

    SAPConnectionPool.ReturnConnection(proxy.Connection);

    This is faster than creating and closing the connection twice.

    ReturnConnection will keep the connection open and store it in a kind of static hashtable with the connection string as key. Later the call to GetConnection will eventually fetch the open connection with fitting connection string from pool. If the open connection is not reused within a certain period, it is automatically closed and removed from the pool.

    So the important thing is SUBSEQUENT and SAME CONNECTION STRING.

    In all other cases the SAPConnectionPool will create new connections, so it would not help.

    I don't understand the code snipped you posted, but it seems somehow useless. Just regard the ConnectionPool as static connection buffer - you don't have to deal with Application state to use it.

    Add comment
    10|10000 characters needed characters exceeded

    • > However, I think the 'used connections counter'

      > should be based on connectionstrings instead of being

      > global: this will improve scalability as we can give

      > more control to the pool balancing.

      Thanks for the feedback. Putting the limit on a per-conection string basis would be possible, but I don't think it would be really usefull: Usually connetion strings are different - at least user name and password differ - even if the point to the same app server.

      Unfortunately it's allmost impossible to detect from a connection string to which server it would exactly go. Imagine that you could use an IP, name with or without DNS domain, load balancing and so forth.

      What could be done and might be usefull is to give you as a user the possibility to hook in your own code that decides whether GetConnection should block or not.

      A feasable way is to offer a static event on Connection

      that is fired on every "opening" connection. What do you think?

      > another question is: is there a timeout for the block

      > that happens to the methods that return a connection

      > when the MaxOpenConnections has reached?

      Currently not. The question would be how to proceed after timeout. Ignore the limit and just open the connection? Or return null from GetConnection?

  • Posted on Jul 07, 2004 at 10:21 AM

    Thanks to both of you for the quick responses!

    Steven

    Add comment
    10|10000 characters needed characters exceeded