Question

I am connecting SAP system with .NET 4.0 using connector.... I have created a sample windows appln to check whether it's connecting or not.. This is my code...

    private void Form1_Load(object sender, EventArgs e)
    {
        try
        {

            SAPSystemConnect sapCfg = new SAPSystemConnect();
            RfcDestinationManager.RegisterDestinationConfiguration(sapCfg);
            RfcDestination rfcDest = null;
            rfcDest = RfcDestinationManager.GetDestination("Dev");

        }
        catch (Exception ex)
        {

           // MessageBox.Show("ERROR");
              label1.text=ex.Message;

        }


    }

Nothing happens when I run this code... Even if i give wrong user name and password in app settings(config file), it's not showing any exception, it's just loading the form...

Can anyone clear my doubt? Do we have any other way to find whether the system is connected?

Était-ce utile?

La solution

SAP Net Connector uses a connection pool. So you usually don't connect or disconnect yourself, the NCo library does that for you. As soon as you actually need a connection it will be established. To simply test your code you could for instance try creating an IRfcFunction instance:

...
rfcDest = RfcDestinationManager.GetDestination("Dev");
IRfcFunction fnc = rfcDest.Repository.CreateFunction("RFCPING");
...

that should trigger the connection. But in general you don't need to open the connection before communicating with the SAP system, you just need to be prepared for the possibility that the connection can't be established (wrong parameters, system is down etc.).

Autres conseils

One thing you can do is Unregister the configuration after work is done by using

RfcDestinationManager.UnregisterDestinationConfiguration(sapCfg);

and next time when you try to connect register it again and use.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top