on 11-06-2014 7:17 AM
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??
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
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?
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.
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
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);
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;
}
}
}
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.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.