Random error when connecting to SAP with ERPConnect
-
17-04-2021 - |
Question
We use ERPConnect in our ASP.NET application but sometimes we get some error messages when users try to connect to SAP through our application.
CPIC-CALL: 'CMRCV : rc=19 LOCATION SAP-Gateway on host SERVERNAME / sapgw10 ERROR Conversation 53230591 not found TIME Wed Nov 16 13:49:58 2011 RELEASE 701 COMPONENT SAP-Gateway VERSION 2 RC 728 MODULE gwxxrd.c LINE 6278 COUNTER 1277701
It always happens when opening a connection to SAP through ERPConnect.
R3Connection connection = Connection;
connection.Open(); // the error occurs here
It's quite random. Some days we don't get any error message, other days we get 20 messages a day. ERPConnect uses librfc32.dll defined in the System32-folder and has version 7200.1.39.6461 (which is a recent version).
This issue didn't occur on my local development machine (Windows 7 x86). It always occurs on our production server (Windows Server 2008 R2).
Any idea what could cause this issue?
Edit (added error log extract):
* * LOCATION SAP-Gateway on host HERCULES / sapgw10 * ERROR partner 'hercules:sapgw01' not reached * * TIME Thu Nov 24 09:10:20 2011 * RELEASE 701 * COMPONENT NI (network interface) * VERSION 38 * RC -10 * MODULE nixxi.cpp * LINE 2835 * DETAIL NiPConnect2 * SYSTEM CALL connect * ERRNO 10061 * ERRNO TEXT WSAECONNREFUSED: Connection refused * COUNTER 1385122 * *****************************************************************************
GwTraceHdlInfo:
HANDLE = 137
TIME = Thu Nov 24 09:10:19 2011
SOCKET = 2108
STAT = NI_CONN_WAIT
TYPE = STREAM IPv4
OUT = 0 messages 0 bytes
IN = 0 messages 0 bytes
LOCAL = 0.0.0.0:1865
REMOTE = -
OPTIONS = BUFFERED
ni hdl = 137
type = CLIENT
net_stat = CONNECT_TO_REM_GW_PENDING
hostaddr = 100.100.103.15
accept_hostaddr = 100.100.103.15
opcode = NORMAL_CLIENT
conn opcode = REMOTE_GATEWAY
conn vers = 2
index = 10
data = 0000000000000000
ext_info = 000000000EF1D870
offset = 0
rest_len = 0
snc_forced = 0
remote gateway infos:
hostname =
hostaddr = 100.100.103.15
service = sapgw01
tpname = sapdp01
GwSelClear: clear RWC for hdl 137
NiICloseHandle: called for hdl 137 while waiting for connection
NiICloseHandle: shutdown and close hdl 137 / sock 2108
GwFreeHdlInfoMemory: free 000000000EF1D870 (ext info)
GwIFreeMemForLU_TP: freed memory for sys 10
GwListRemove: remove elem 10 from sys_r3_list
GwListRemove: 2 elems in sys_r3_list
GwListRemove: elem 10 not in sys_reg_list
GwListRemove: remove elem 10 from sys_inuse_list
GwListRemove: 104 elems in sys_inuse_list
GwUpdateClient: act_sys: 104
GwIDelR3Conn: send error message to client
GwSendRc3: send (appc_rc=CM_PRODUCT_SPECIFIC_ERROR / sap_rc=GW_CONNECT_FAILED) to client HERCULES / sapgw10 (0)
GwRqDpSendTo: (HERCULES / sapgw10, gw_id=0, appc_ca_blk=-1, len=335, comm_index=-1)
LOCK APPC ca_blk 3
DpGetCpicCommIdx: found index 3 via appc_hdr
found comm entry 3 (tid/uid/mode/conv_id/a_r: 158/13268/0/ /0)
GwIsAWaitingSWP: wp 1 waiting
GwSapWpWakeUp: send answer to sap wp 1
GwSapWpWakeUp: make wp 1 owner of appc_ca_blk 3
-OUT- tid -1 uid -1 mode 255
-OUT- appc_ca_blk 3 len 335 rq_id 43133
-OUT- wait_f_answ 0 cmd 0
NiIWrite: hdl 109 sent data (wrt=28,pac=1,MESG_IO)
GwIDelR3Conn: decrement conv_no of client 0: 5
GwFreeMemory: free 000000000EEF3480 (len=3700)
GwFreeMemory: act_overflow_size = 20352 (- 3700)
GwIDelR3Conn: idx/conv = ((-1/0) | (10/0)), delete conv 48 from conv-table
GwClearConn: conv_no/tcp_conv_no/sna_conv_no: 6/6/0
GwClearConn: free r3 conv info
GwClearConn: free buffer info
GwFiSearchConvId: deleted 27077110 local, conn=48
GwListInsert: insert elem 48 into conn_free_list (at begin)
GwListInsert: 494 elems in conn_free_list
GwListRemove: remove elem 48 from conn_search_list
GwListRemove: 0 elems in conn_search_list
GwListRemove: elem 48 not in conn_write_list
GwListRemove: remove elem 48 from conn_inuse_list
GwListRemove: 6 elems in conn_inuse_list
GwReadReqIndex: (process_id: -1)
GwReadReqIndex: no filled request-index-block
GwCheckClient: check clients
LOCK APPC ca_blk 4
GwCheckClient: raise timeout for conv 27059938 (intr/uid/mode/comm_idx=9/13261/0/90)
GwSendRcToDp: send appc_rc/sap_rc 10001/221 to dp
make DISP owner of appc_ca_blk 4
DpSemRq: key: 3, units: 1, timeout: -1
DpSemRel: key: 3, units: 1
DpRqPutIntoQueue: put request into queue (reqtype 0, prio LOW, rq_id 43134)
GwDispWakeUp: send wakeup with ni handle 2
NiIWrite: hdl 2 sent data (wrt=1,pac=1,MESG_IO)
-OUT- sender_id APPC_SERVER tid 165 wp_ca_blk -1 wp_id -1
-OUT- action SEND_TO_WP uid 13261 appc_ca_blk 4 type NOWP
-OUT- new_stat NO_CHANGE mode 0 len 80 rq_id 43134
GwListRemove: remove elem 90 from comm_wait_list
GwListRemove: 0 elems in comm_wait_list
GwListRemove: remove elem 90 from comm_wait_list
GwListRemove: 0 elems in comm_wait_list
Edit 2: added code example
I've created a little code example and if noticed that at the end one connection remains open. If I start the example again, two connections remain open at the end of the example. So something is going wrong...
protected void SAP( object sender, EventArgs e ) {
ThreadStart threadStart1 = new ThreadStart( CreateSAP );
Thread thread = new Thread( threadStart1 );
Thread thread2 = new Thread( threadStart1 );
thread.Start();
Thread.Sleep( 2000 );
thread2.Start();
while ( thread2.IsAlive ) {
}
Response.Write( "done" );
}
private void CreateSAP() {
R3Connection conn = ERPConnection.Connection;
conn.MultithreadingEnvironment = true;
for ( int i = 0; i < 12; i++ ) {
try {
conn.Open();
Thread.Sleep( 1000 );
} finally {
conn.Close();
}
}
}
La solution
Unfortunately it was something I did in my code which wasn't very... euh... nice. ERPConnect has a R3Connection-object and I used a singleton throughout my whole application.
If a connection was in use by a user while another user also requested a connection, the R3Connection-object created a new connection (you can verify this by using the SM04-transaction in SAP). If both users however closed the connection, one of the two connections remained open (I think this a bug in ERPConnect but we can't contact them because our support is expired for now). The limit of connections (defined in SAP) is reached quickly off course in a production environment.
I now create a R3Connection-object for each user so I'm sure the connection is properly closed in the SAP-system when calling the Close() method (or using statement) in my code.
Code
public static R3Connection Connection {
get {
ERPConnect.LIC.SetLic( "MyLicenseKey" );
R3Connection connection = new R3Connection(
[set connection settings]
);
connection.MultithreadingEnvironment = true;
return connection;
}
}
Autres conseils
I'm hunting around for the answer to a completely different problem, but seeing as I've stumbled across yours, this looks very much like network configuration - make sure that your SAP server "hercules" has ports 3210, 3310 and 3610 (I think those are right - might be 3201/3301/3601, tough to tell from SMGW logs) open in Windows Firewall, that there aren't any other firewalls blocking relevant traffic, and that the default gateway on "hercules" is set to a device which can successfully route traffic to 100.100.103.15 (I'm assuming, from your logs, that that's the IP address of your server on which the .NET application is running), and that the default gateway on 100.100.103.15 is set to a device which can successfully route traffic to "hercules". Furthermore, you'll have better luck if you use a fully qualified domain name (e.g. hercules.sap.local) to make the connection to your SAP server, because then you're no longer reliant on the prehistoric vagaries of NetBIOS to find your SAP server.