cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with server connections (NCo 2.0, C#)

Former Member
0 Kudos

Hello all.

I have written a SAP server (.NET Connector 2.0, C#, runs as service) which opens

3 server connections to SAP.

From the SAPServerHost class I have derieved my own class

and overwritten the callback function OnServerException.

When this function is triggered by disconnecting my server from the network

I call the Stop method of the host instance.

In a separat thread I call the hosts Start method in intervalls

(like every minute) to try to reconnect to SAP again.

After reconnecting my server to the network the host is restarted and opens

3 connections to SAP again.

Problem:

When I monitor my server connections in SAP (SMGW) I see 6 server connections

after reconnecting my server.

There are 3 corrupt connections that remain visible and which

I have to kill from within SMGW.

Question:

Are these 3 connections cleaned up by SAP after a while ?

Do I have to clean them up from within my server and if yes how do I do that ?

Here is my OnServerException method:

public override SAP.Connector.ActionOnServerException OnServerException(SAP.Connector.SAPServer server, System.Exception e)

{

if((this.ServerHostStatus != SAPServerStatus.Stopped) &&

(this.ServerHostStatus != SAPServerStatus.StopPending))

{

this.Stop();

}

return SAP.Connector.ActionOnServerException.AutoReconnect;

}

Thanks a lot for all responses in advance,

cheers

Fred

Accepted Solutions (0)

Answers (9)

Answers (9)

Former Member
0 Kudos

Thanks very much Rennie. The problem was very much with the server program.

Rgds,

Aravinda Sarma M.

Former Member
0 Kudos

Hi,

Am facing a peculiar problem in this regard. The service is working fine on my system. But when it is deployed on a system where there is only the .net framework installed its not working.

Can anyone please tell me what could be the reason for this?

Rgds,

Aravinda Sarma M.

reiner_hille-doering
Active Contributor
0 Kudos

On the target machine you need:

- The fitting .NET Framework.

- Your App.

- SAP.Connector.DLL and SAP.Connector.Rfc.DLL, eiher in your app-dir or in GAC.

- LIBRFC32.DLL either in your app-dir or in System32.

- SAPLOGON.INI in windir, if you use a SAPLogonDestination that refers to it.

- The corresponding entries in system32\drivers\etc\services, especially all needed sapms<SID>.

Anything that is missing should create an exception that explains the missing piece.

Former Member
0 Kudos

Hi Reine,

All these files have been deployed and the service is running successfully. But when I call the RFC it gives a short dump

'Exception condition "TARGET_METHOD_EXCEPTION" raised'.

This exception is occuring at the function call level. The RFC Destination is working fine.

Can you tell me what could be the reason?

Rgds,

Aravinda Sarma M.

reiner_hille-doering
Active Contributor
0 Kudos

It seems that your RFC-Server is throwing an exception that is transported to ABAP as shortdump.

You should attach a debugger (VS) and turn on "Fist chance exception breaking".

Former Member
0 Kudos

in my case SAP picked any of those shown

connections.

when it took one of the "garbage" ones,

the system seemed to hang for like 1 or 2 minutes

and then a SAP message box "System error" appeared.

after that the garbage connection finally got killed.

when lucky, SAP picked a "good" one and everything

was ok.

by the way, this behaviour also occurs when i manually

stop one of the servers in my SAPHost class.

since i am writing a server for SAPphone this kind

of behavior is not very good.

after i reconnect i would expect everything to work.

i cannot expect SAP CIC or SPHT users to have their system

hang after reconnection for a couple of minutes

if they have "bad luck".

any ideas how i can get around this or will there be a fix sometimes ?

thanks a lot.

best regards,

fred

Former Member
0 Kudos

Hi Alfred,

An update on this issue:

I discussed this issue with the developer responsible for SAP gateway. According to him, what you experienced is somehow by design. Because the SAP gateway doesn't get evented at network layer when a registered connection get broken, it has no way to detect the broken connection immediately and remove it from its connection list. The only way for gateway to determine if a registered connection is "bad" or still "good" is to "talk" to it. But talking to a broken connection is not cheap and should not be performed too often.

The gateway profile parameter gw/reg_keepalive (in seconds) determines how often the gateway will send keep-alive message to all registered connections. The default value is 300, you can use a smaller value to allow the gateway to detect a "bad" connection sooner.

Hope it helps somehow although it is far away from a perfect solution.

Guangwei

Former Member
0 Kudos

Hi Guangwei.

Thank you very much for your help

Best regards,

Fred

Former Member
0 Kudos

hello.

any news on this issue ?

Former Member
0 Kudos

Hi,

I was able to reproduce the problem with DNC 2.0.1 by disabling and enabling the network connection. After reconnecting, both the "garbage" connections and the "good" new connections were listed in SMGW. However, if keeping clicking the refresh button for a while(about 1 minute), those corrupt connection will be removed from the list.

I think it is just an issue of timing when SAP gateway updating its connection list. Even with "bad" connections listed in SMGW, all my RFC connection tests worked just fine. It seems that the gateway is taking care for choosing only "good" connection for the RFC calls.

Did you experience any real connection problem due to those "garbage" connections in SMGW?

Regards,

Guangwei

Former Member
0 Kudos

Yup. By disconnecting I mean plugging out my cable.

Thanks a lot for your efforts

Best regards,

Fred

Former Member
0 Kudos

Hi Guandwei.

Here is a code excerpt of what I am doing:

I start a host instance with 3 server threads.

After disconnecting my server from the network

and reconnecting it again I can see 6 connections

in SMGW, 3 of them cause the SAP GUI to hang

('System error' message box after 1 to 2 minutes)....

/////////////////////////////////

// This is how I initially start my server ....

ServerHost host = new ServerHost();

// Server stuff

if(host != null)

{

SAPServer server = null;

string[] sDest = {sys.sDest};

for(int j = 1; j <= 3; j++)

{

server = new SAPProxy1Impl(sDest, host);

if(server == null)

{

// tracing...

}

else

{

// tracing...

}

} // for

try

{

host.Start();

}

catch(Exception e)

{

// tracing...

}

}

////////////////////////////////////////////

// After network disconnection or after I stop a SAPServer instance

// this callback function is triggered ....

public override SAP.Connector.ActionOnServerException OnServerException(SAP.Connector.SAPServer server, System.Exception e)

{

return SAP.Connector.ActionOnServerException.Terminate;

}

/////////////////////////////////////////////

// In a reconnect thread I reconnect the SAPServer ...

static public void SAPServerReconnectThread()

{

while(m_bSAPServerReconnect)

{

foreach (SAPServer server in sys.SAPHost.Components)

{

if(server.ServerStatus == SAPServerStatus.Stopped)

{

server.Start();

}

}

Thread.Sleep(globals.iSAPReconnectSleep);

} // while

}

///////////////////////

Former Member
0 Kudos

Hi,

You mean plugging-out your network cable when you say "disconnecting" your server? I will investigate this situation further. I believe that it is an issue of the SAP gateway.

Regards,

Guangwei

Former Member
0 Kudos

Yes,

even after clicking refresh ....

Former Member
0 Kudos

If so, I would like to have a look at your code. Can you email it to me? A simplified version that can show the problem is enough.

Regards,

Guangwei

Former Member
0 Kudos

Hi Guangwei.

Thank you very much for your response.

I tried it the way you suggested but the problem

still remains the same.

This is, after I restart a server that was stopped

by disconnecting my server from the network or by

calling the servers Stop method, the disconnected

connection remains visible in SMGW in SAP.

So, if SAP as a client makes a call to my server

it can happen that it tries to use such a zombie

connection which causes the SAP GUI to hang.

Am I still missing something in my server code ?

Thanks a lot again.

Best regards,

Fred

Former Member
0 Kudos

Hi,

Even after clicking the "Refresh" button in SMGW?

Guangwei

Former Member
0 Kudos

Hi Fred,

If you just want to stop the RFC server instance that is currently calling the callback and try to re-start the instance sometime later, you do not need to call

this.Stop()

from within your overridden callback. What you need here is just to "remember" the current server instance and then return with ActionOnServerException.Terminate. After return, the calling instance(actually the thread) will stop to run. The return value ActionOnServerException.Reconnect will cause the current server instance to re-connect automatically and immediately. The value ActionOnServerException.AutoReconnect should also cause

the running instance to re-connect, but after a configurable delay. However, there is a bug with the value "AutoReconnect" in the current, and previous versions of the .NET Connector. Please do not use this value until the next patch.

Also, please note that the method SAPServerHost.Stop will stop ALL running RFC server instances contained in the server host. The class SAPServer has its own Stop() method.

So, your overridden method should look like:

public override SAP.Connector.ActionOnServerException OnServerException(SAP.Connector.SAPServer server, System.Exception e)

{

//somehow "remember" that the server instance specified

//by the parameter "server" needs to be re-started if you

//like

return SAP.Connector.ActionOnServerException.Terminate;

}

You can later try to restart the stopped instances somehow like this:

foreach (SAPServer server in host.Components)

{

if(server.SAPServerStatus == SAPServerStatus.Stopped)

server.Start();

}

Hope it helps,

Guangwei