cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Connection String in ConfigDestination from app.config

Former Member
0 Kudos

Hello,

I am unable to retrieve the connection string from app.Config file using ConfigDestination in .Net Connector 2.x

The following is the snap shot of app.config file portion

<appSettings>

<add key="DestinationName" value = "ASHOST=xxx.xx.x.xxx SYSNR=0 CLIENT=100 USER=UID PASSWD=PWD" />

</appSettings>

And I am trying to extract this with the follwoing c# code

sapLogonDestination1 = new ConfigDestination ("DestinationName");

_proxy.Connection = new SAP.Connector.SAPConnection(sapLogonDestination1);

But unfortunately this piece of code is not working the way it should

Thanks all in advance

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You mean, that we can't do something like:

1. Add "using System.Configuration;" to the using statement area.

2. Use "string ConnectionString = ConfigurationSettings.AppSettings["ConnectionString"].ToString();"

where "ConnectionString" is a key in the <appSettings> area in the app.config file?

reiner_hille-doering
Active Contributor
0 Kudos

> 1. Add "using System.Configuration;" to the using

> statement area.

>

> 2. Use "string ConnectionString =

> ConfigurationSettings.AppSettings["ConnectionString"].

> ToString();"

>

> where "ConnectionString" is a key in the

> <appSettings> area in the app.config file?

Of cause this is also an option, but this is not what I meant. I meant the usage of Destination and ConfigDestination in conjunction with ASPX/ASMX/Windows Forms/Component Designers.

If you drag a "Destination" from the "SAP Proxy" toolbox to one designer an maintain settings like Username or AppServerHost, they would normally go into code. Each property can be marked as a so-called "Dynamic Property". The property is maked with a little blue icon in the property window and the value is automatically written to appSettingse, e.g.

  <appSettings>
    <!--   Example: <add key="settingName" value="settingValue"/> -->
    <add key="destination1.AppServerHost" value="host" />
    <add key="destination1.Client" value="0" />
  </appSettings>

Some important properties are automatically marked so, but you can freely change it.

The ConfigDestination behaves similar, but has an easier to maintain schema. Just drop a ConfigDestination from the toolbox to a designer and configure it in the properties window. You will automatically find the correct entries in the config file.

Former Member
0 Kudos

Thanks Reiner,

I know how to extract information from appSetting element, but sure, I was looking from ConfigDestination perspective...

Answers (1)

Answers (1)

reiner_hille-doering
Active Contributor
0 Kudos

The ConfigDestiantion has an own schema to store its data. It doesn't use appSettings. Please see online documentation for class "Config" for details (ms-help://MS.VSCC.2003/SAP.NCO/NCOV2Docu/reference/SAP.Connector.Config.html).

If you want to have the settings in appSettings, use a standard "Destination" instance in conjunction with Visual Studio's "Dynamic Properties" feature.