cancel
Showing results for 
Search instead for 
Did you mean: 

.Net Connector Connection pooling help

Former Member
0 Kudos

have an app deployed using Nco 2003(1.3?). Whenever data is needed from SAP a class is called and Nco is used to do a read with a custom READTable BAPI.

Most of the sites that the app is deployed to have no issue. But one in particular, the one that has the most users, continually gets:

"Connect to SAP gateway failed Connect_PM DEST=..., GWHOST=... GWSERV=..., ASHOST=..., SYSNR=... LOCATION CPIC (TCP/IP) on local host ERROR max no of 100 conversations exceeded"

The best we could find was that this had to do with connections not being returned to the pool, etc. I optimized code always use SAPConnectionPool.GetConnection and ReturnConnection. In addition, the code that calls the BAPI is in a using block, to further ensure quick release.

The connection string is always the same.

The customer has set CPIC_MAX_CONV as high as 600 and it still happens.

After the optimization, we thought we had it fixed, but apparently the problem still continues. At one point I looked into upgrading them to NCo 2.0. This is still an option if someone can tell me that it would buy me significant improvement.

Please, can someone look at this code and tell me if there's something that would help?

using(rfcGetADRP rfc = new rfcGetADRP))

{ //Trace.WriteLineIf(_TraceSwitch.Level >= TraceLevel.Verbose,"Opening connection..."); TraceConfig.WriteVerbose("Opening Connection");

rfc.Connection = SAPConnectionPool.GetConnection(_ConnectionString);

ADRPTable ADRP = new ADRPTable();

//CALL RFC

rfc.Z_Acsis_Getadrp(_MaxRows,ref ADRP,ref rfcfields,ref rfcoptions,ref rfcorderBy);

SAPConnectionPool.ReturnConnection(rfc.Connection);

rfc.Connection = null;

//format and return;

_dtOutput = ADRP.ToADODataTable();

DataSet ds = new DataSet();

ds.Tables.Add(_dtOutput);

return ds; }

Accepted Solutions (0)

Answers (1)

Answers (1)

reiner_hille-doering
Active Contributor
0 Kudos

Your code seems to be Ok. If you execute it sequentially, it should consume exaclty 1 connection (assuming that _ConnectionString remains constant).

If the block is executed in parallel (on multiple threads), you could however create an unlimited number of connections.

Have you checked in backend (I think transaction SMGW) that all the connections have been created by you application?

NCo 2.0 is much more flexible in connection pooling. It allows e.g. to define an upper limit of connection that NCo is allowed to allocate. Above the value the demanding thread would block. So even in the concurrent case you could limit the maximum connection to say 50.

Former Member
0 Kudos

We have checked the backend and all the connections are created by our application. We have written a Web front-end using .Net connector. All the code for this is executed sequentially. We have used the code mentioned previously for reading from SAP via RFC. We get a connection from the connection pool and return it to the connection pool for each RFC.

We would expect this process to result with one connection per user, however, at a site with 25 concurrent users, we are exceeding 100 connections.

Please advise

reiner_hille-doering
Active Contributor
0 Kudos

The connection pool reuses connections with exactly the same connection string. It only works as expected if:

- Many "usages" share the connection string.

- At least some usages are sequential.

E.g.

string connStr1 = ...
string connStr2 = ...

Connection con;

con = SAPConnectionPool.GetConnection(connStr1); // first conn created
SAPConnectionPool.ReturnConnection(con);
con = SAPConnectionPool.GetConnection(connStr2); // second conn created
SAPConnectionPool.ReleaseConnection(con);
con = SAPConnectionPool.GetConnection(connStr1); // first reused
SAPConnectionPool.ReturnConnection(con);
con = SAPConnectionPool.GetConnection(connStr2); // second reused
SAPConnectionPool.ReturnConnection(con);

In the sample before you would have exactly 2 connection.

You could unintentionally create more if:

- You have more different connection strings

- Or mutiple "GetConnection" calls come in concurrently before other "ReturnConnection".