cancel
Showing results for 
Search instead for 
Did you mean: 

sap nco 3.0 error destination configuration already initialized even after unregistering.

Former Member
0 Kudos

I am using SAP nco 3.0 connector to connect to sap and get data, it works well on many systems, but for few of the system it throws error.

Please can some one guide me what I have missed??

Accepted Solutions (0)

Answers (1)

Answers (1)

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Prithvi,

what is the exact error? Please note, that you need the very same instance for unregistration like the one you used for registration. But actually, normally you never unregister - this should be a very rare situation ....

Best regards,

Markus

Former Member
0 Kudos

Error: "destination configuration already initialized"

In some systems it works properly.
Eg: Windows 7 32 bit and 64 bit the code runs properly. But in some system with same config it throws error.

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Prithvi,

this means that there is already an implementation of  IDestinationConfiguration registered in that environment, i.e. destinations are retrieved from some alresdy defined place. Separate that part from your application code, the destination parts should only be needed in environments, in which there isn't a destination configuration. The application code should then simply use the destiination via RfcDestinationManager and if it's not there, an administrator of that host has forgotten to do his job and has not configured the destination.

Best regards,

Markus

Former Member
0 Kudos

Hi Markus,

The problem got solved, I changed the class name of the IDestinationConfiguration implementation and the code worked for me. I think might be the garbage collection issue.

Now i have invoked the garbage collector after unregistering the destination.

hynek_petrak
Active Participant
0 Kudos

Hi Prithvi,

could you explain, why do you unregister the destination? Why is it necessary in your situation?

Former Member
0 Kudos

Hi Hynek,

I tried both ways i.e. unregistering and registering destination.

Unregistering did run smoothly for me. But without unregistering I get a null value for RfcDestinationManager.TryGetDestination(destination) & RfcDestinationManager.RegisterDestinationConfiguration(destination) throws "destination configuration already initialized" error.

hynek_petrak
Active Participant
0 Kudos

Hi Prithvi,

this is a wrong approach. As Marcus has been hinting above ...

If you need to implement your own IDestinationConfiguration, then register it (RegisterDestinationConfiguration) at the application start up, once and for the whole life time of the application.

For ASP.NET in Application_OnStart(). For WPF in Application.Startup event or MainWindow constructor. For Winforms, console application at the very beginning of the Main().

Register it before any call to GetDestination(xx) may occur.

Is that possible in your case?

Former Member
0 Kudos

Hi Hynek,

I have implemented IDestinationConfiguration, and registered in the constructor of the Windows form.

I did add unregistering code as the application sometimes fails to connect to sap.

hynek_petrak
Active Participant
0 Kudos

You shall analyze the reason, why your applications fails to connect "sometimes". Does the form lives the  whole lifetime of the application? What is the error message, when you cannot connect?

Former Member
0 Kudos

yes the form is alive for the complete lifecycle of the application.

private void Form_Load(object sender, EventArgs e)

{

       SAPConnection _SapConnection = new SAPConnection();

       RfcDestinationManager.RegisterDestinationConfiguration(_SapConnection);

}

Here SAPConnection is the IDestinationConfiguration implementation class.

I encounter error for:

RfcDestination _rfcDestination = RfcDestinationManager.GetDestination(_dllConfigAppSettings.Settings["AppServerHost"].Value);

Error: Object reference not set to an instance of an object.
Error: destination configuration already initialized

Sometimes I face the above mentioned error, not always.

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Prithvi,

obviously, there is some other IDestinationConfiguration already registered. Please note that the IDestinationConfiguraiton used, is considered a singleton, which is retrieving the configuration data of the destination from the location where destinations are supposed to be stored in that environment. If the destination you lookup is not stored there, you will get returned null. And if the Form_Load method is executed more than once, you will get an issue.

But the object reference issue is more likely in (_dllConfigAppSettings.Settings["AppServerHost"].Value. You need to check what's null there.

Best regards,

Markus

hynek_petrak
Active Participant
0 Kudos

Hi Prithvi,

please paste also your implementation of SAPConnection. The issue might be there.

Hynek

Former Member
0 Kudos

Hi Markus,

To solve the destination configuration already initialized issue I did put  RfcDestinationManager.UnregisterDestinationConfiguration(_SapConnection); at the end.

because when I close and open the form, the form_load is triggered which results into registering SAP connection and throws the above error

Also I tried adding the code below to handle the error, but got a null value for destination

RfcDestination dest = RfcDestinationManager.TryGetDestination(_dllConfigAppSettings.Settings["AppServerHost"].Value);

                if (dest == null)

                    RfcDestinationManager.RegisterDestinationConfiguration(_SapConnection);

Former Member
0 Kudos

Hi Hynek,

SAPConnection code:

using System.Configuration;

using SAP.Middleware;

using SAP.Middleware.Connector;

namespace SAPData

{

    class SAPConnection : IDestinationConfiguration

    {

       

        public RfcConfigParameters GetParameters(string destinationName)

        {

            RfcConfigParameters parms = new RfcConfigParameters();        

            parms.Add(RfcConfigParameters.AppServerHost, dllConfigAppSettings.Settings["AppServerHost"].Value);

            parms.Add(RfcConfigParameters.SystemNumber, dllConfigAppSettings.Settings["SystemNumber"].Value);

            parms.Add(RfcConfigParameters.User, dllConfigAppSettings.Settings["User"].Value);

            parms.Add(RfcConfigParameters.Password, dllConfigAppSettings.Settings["Password"].Value);

            parms.Add(RfcConfigParameters.Client, dllConfigAppSettings.Settings["Client"].Value);

            parms.Add(RfcConfigParameters.Language, dllConfigAppSettings.Settings["Language"].Value);

            parms.Add(RfcConfigParameters.PoolSize, dllConfigAppSettings.Settings["PoolSize"].Value);

            parms.Add(RfcConfigParameters.PeakConnectionsLimit, dllConfigAppSettings.Settings["PeakConnectionsLimit"].Value);

            return parms;

        }

        RfcDestinationManager.ConfigurationChangeHandler changeHandler;

        public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged

        {

            add

            {

                changeHandler = value;

            }

            remove

            {

                //Do nothing.

            }

        }

        public bool ChangeEventsSupported()

        {

            return true;

        }

      

    }

}

hynek_petrak
Active Participant
0 Kudos

Hello Prithvi,

if you say "because when I close and open the form, the form_load is triggered " it means the form does not exist for the whole lifetime of the application. Please move RfcDestinationManager.RegisterDestinationConfiguration(_SapConnection); to the Main(); Move it away from the Form object.