cancel
Showing results for 
Search instead for 
Did you mean: 

SAP NCo 3.0 RfcDestinationManager error

Former Member
0 Kudos

Hi,

I'm developing a simple Web application with Visual Web Developer 2010 and SAP NCo 3.0. I followed all the required steps to connect to SAP and the application worked fine implementing IDestinationConfiguration class. Now I wanted to take the connection settings away from code and put them in web.config.

The problem comes in this line

RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination(APP_SERVER);

The error states "Cannot get destination E30 -- no destination configuration registered"

Previously I was using the method RegisterDestinationConfiguration(config), being config a IDestinationConfiguration instance.

RfcDestinationManager.RegisterDestinationConfiguration(config);

But this is no longer needed since the destination is configured in the web.config.

I enclose the code:

web.config

<?xml version="1.0" encoding="utf-8"?>

 

<configuration>

  <configSections>

        <sectionGroup name="ClientSettings">

        <section name="DestinationConfiguration" type="SAP.Middleware.Connector.RfcDestinationConfiguration, sapnco" />

      </sectionGroup>

    </sectionGroup>

  </configSections>

 

  <SAP.Middleware.Connector>

        <ClientSettings>

      <DestinationConfiguration>

        <destinations>

          <add NAME="E30" SYSID="E30"   MSHOST="saphost" MSSERV="sapmsprod"

               SYSNR="10" CLIENT="001"  GROUP="GR09" USERNAME="user" PASSWD="pass"

               LANG="EN"  POOL_SIZE="5" IDLE_TIMEOUT="600"/>

        </destinations>

      </DestinationConfiguration>

    </ClientSettings>

   

  </SAP.Middleware.Connector>

 

  <system.web>

    <compilation debug="true" targetFramework="4.0" />

  </system.web>

 

</configuration>

Main class main.aspx

sing System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Diagnostics;

using SAP.Middleware.Connector;

namespace SAPRelease {

    public partial class WebForm1 : System.Web.UI.Page     {

        protected void Page_Load(object sender, EventArgs e)         {

            const string APP_SERVER = "E30";

            //RfcDestination prd = null;

            String hash = Request.QueryString["doc_id"];

            if (hash == null) {

                ExceptionText.Text = "No hash string";

            }

            else {

                try {

                        //ECCDestinationConfig config = new ECCDestinationConfig();

                        //RfcDestinationManager.RegisterDestinationConfiguration(config);

                        //prd = RfcDestinationManager.GetDestination(destinationName);

 

                        RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination(APP_SERVER);

                        RfcRepository SapRfcRepository = SapRfcDestination.Repository;

 

                        IRfcFunction poRelease = SapRfcRepository.CreateFunction("Z_TEST");

                        poRelease.SetValue("IMPORT", hash);

                        poRelease.Invoke(SapRfcDestination);

                         // Process Function Module return

                        String fmReturn = poRelease.GetString("EXPORT");

                         ExceptionText.Text = fmReturn;

                       

                    }

                    catch (RfcLogonException ex) {

                        ExceptionText.Text = ex.Message;

                    }

                    catch (RfcCommunicationException ex) {

                        ExceptionText.Text = ex.Message;

                    }

                    catch (RfcAbapRuntimeException ex) {

                        ExceptionText.Text = ex.Message;

                    }

                    catch (RfcAbapBaseException ex) {

                        ExceptionText.Text = ex.Message;

                    }

                    catch (RfcInvalidStateException ex) {

                        ExceptionText.Text = ex.Message;

                    }

                    catch (NullReferenceException ex) {

                        ExceptionText.Text = ex.Message;

                    }

                    catch (IndexOutOfRangeException ex) {

                        ExceptionText.Text = ex.Message;

                 

Any clue how to fix it? Since it was working with hardcoded config shouldn't be too difficult.

Regards,

Salva.

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

Dear expert,

What does this "RfcDestinationManager.RegisterDestinationConfiguration(config)" work for? 

Originally, I use IDestinationConfiguration and RfcDestinationManager.RegisterDestinationConfiguration(config) to get a connection, but it occasionally gets the error "destination configuration already initialized".    Therfore, I put my connection string in web.config, and use RfcDestinationManager.GetDestination(destinationName) directly to avoid that error. 

Will this cause a problem since I do not declare RegisterDestinationConfiguration??

thanks,

Zita

hynek_petrak
Active Participant
0 Kudos

You may avoid double registering by the below check. However the below check assumes, that the "dest" destination is known by your IDestinationConfigurationImplementation. Otherwise you may want to implement another kind Singleton pattern.

RfcDestination getDestination(dest as string) {

    IDestinationConfiguration _destConfig = new IDestinationConfigurationImplementation();

    if (RfcDestinationManager.TryGetDestination(dest) == null) {

         RfcDestinationManager.RegisterDestinationConfiguration(_destConfig);

    }

    return RfcDestinationManager.GetDestination(dest);

}

0 Kudos

Thank you Hynek for your input.  Currently, I changed my code a little bit.  I do not write "RfcDestinationManager.RegisterDestinationConfiguration" before calling "RfcDestinationManager.GetDestination" but use "RfcDestinationManager.GetDestination" directly instead.   Will this re-writing cause any problem?  When will the connection get released?

Zita

hynek_petrak
Active Participant
0 Kudos

If you do not call RegisterDestinationConfiguration, then the source for the connection details will be the application config. Purpose of your own IDestinationConfiguration is to provide different source for connection details. So to answer your

1st question => it depends on what you want to achieve (where you store your connection details)

2nd question => connection release is managed by .NET connectors' own connection pool. You can control the behavior with RfcConfigParameters.PeakConnectionsLimit and mainly RfcConfigParameters.PoolSize. Those are parameters of RfcConfigParameters.

0 Kudos

Dear expert,

What does this "RfcDestinationManager.RegisterDestinationConfiguration(config)" work for? 

Originally, I use IDestinationConfiguration and RfcDestinationManager.RegisterDestinationConfiguration(config) to get a connection, but it occasionally gets the error "destination configuration already initialized".    Therfore, I put my connection string in web.config, and use RfcDestinationManager.GetDestination(destinationName) directly to avoid that error. 

Will this cause a problem since I do not declare RegisterDestinationConfiguration??

thanks,

Zita

former_member197445
Contributor
0 Kudos

The first thing I see is the missing SAP.Middleware.Connector line, as shown in the first section below.  If that doesn't do it, you can also try connecting directly to an application server as shown in the second section below.

   <sectionGroup name="SAP.Middleware.Connector">     

      <sectionGroup name="ClientSettings">

        <section name="DestinationConfiguration" type="SAP.Middleware.Connector.RfcDestinationConfiguration, sapnco"/>

      </sectionGroup>     

    </sectionGroup>

...

<add NAME="E30" USER="XXXX" PASSWD="pass" CLIENT="001" LANG="EN" ASHOST="eccserver01" SYSNR="00" POOL_SIZE="5" MAX_POOL_SIZE="10"/>

Former Member
0 Kudos

Hi Case,

Thanks for your reply. The first code is correct. I modified the code before posting and SAP.Middleware.Connector appears.

About the second section, I don't know much about SAP Basis, but AFAIK I must connect to logon group instead application server instead, and since it was working I assume it as valid configuration.

I realized you must use "using System.Configuration" in order to link config file with source code, but this is a C# particular question.

Thanks anyway.

Regards.

hynek_petrak
Active Participant
0 Kudos

Hi Salvador, Case,

there is similar unswered post for the same topic already:

http://scn.sap.com/thread/3402135

I'm not sure whether .NET connector supports web.config as source for destinations ....

Hynek

former_member197445
Contributor
0 Kudos

I am revisiting this issue since it recently happened to me again.  The problem was that sapnco and sapnco_utils DLLs were set to "False" for "Copy Local" setting in Project References.  Setting those to true alleviated the issue.