问题
When i try to connect to SAP server dynamically I am getting error like
Hard-coded logon parameters not allowed when using a Destination Configuration
any one plz help me
I need to send all parameters from codebehind Dynamically not from Web.config
from web.config its working fine .. but not here
My code is like this
SAPSystemConnect objSapConfig = new SAPSystemConnect();
RfcDestination objSapdestination = null;
RfcDestinationManager.RegisterDestinationConfiguration(objSapConfig);
RfcConfigParameters objParameter = new RfcConfigParameters();
objParameter.Add(RfcConfigParameters.AppServerHost, Convert.ToString("XXX"));
objParameter.Add(RfcConfigParameters.Client, Convert.ToString("XXX"));
objParameter.Add(RfcConfigParameters.Password, Convert.ToString("XXX"));
objParameter.Add(RfcConfigParameters.SystemNumber, Convert.ToString("XXX"));
objParameter.Add(RfcConfigParameters.User, Convert.ToString("XXX"));
objParameter.Add(RfcConfigParameters.Language, Convert.ToString("XXX"));
objParameter.Add(RfcConfigParameters.LogonGroup, Convert.ToString("XXX"));
objParameter.Add(RfcConfigParameters.PoolSize, Convert.ToString("XXX"));
objParameter.Add(RfcConfigParameters.PeakConnectionsLimit, Convert.ToString("5"));
objParameter.Add(RfcConfigParameters.IdleTimeout, Convert.ToString("XXX"));
//objParameter.Add(RfcConfigParameters.Name, Convert.ToString("XXX"));
objSapdestination = RfcDestinationManager.GetDestination(objParameter);
RfcCustomDestination customDest = objSapdestination.CreateCustomDestination();
IRfcFunction func = customDest.Repository.CreateFunction("XXX");
RfcRepository objSapRepository = objSapdestination.Repository;
// Calling Sap Function
IRfcFunction objSapDataFunction = objSapRepository.CreateFunction(Convert.ToString("XXX"));
objSapDataFunction.SetValue("XXX", "XXX");
objSapDataFunction.Invoke(objSapdestination);
// Filling SapData into Table
IRfcTable objSapTable = objSapDataFunction.GetTable(Convert.ToString("GIT_DATA"));
回答1:
Check this out. This is a just a demo code.
public class Program
{
static void Main(string[] args)
{
SapConnection con = new SapConnection();
RfcDestinationManager.RegisterDestinationConfiguration(con);
RfcDestination dest = RfcDestinationManager.GetDestination("NSP");
RfcRepository repo = dest.Repository;
IRfcFunction fReadTable = repo.CreateFunction("ZSOMA");
fReadTable.SetValue("I_NRO1", 1);
fReadTable.SetValue("I_NRO2", 2);
fReadTable.Invoke(dest);
var result = fReadTable.GetValue("E_RESULT");
Console.WriteLine(result.ToString());
Console.ReadLine();
}
}
public class SapConnection : IDestinationConfiguration
{
public RfcConfigParameters GetParameters(string destinationName)
{
RfcConfigParameters conf = new RfcConfigParameters();
if (destinationName == "NSP")
{
conf.Add(RfcConfigParameters.AppServerHost, "sap-vm");
conf.Add(RfcConfigParameters.SystemNumber, "00");
conf.Add(RfcConfigParameters.SystemID, "xxx");
conf.Add(RfcConfigParameters.User, "yourusername");
conf.Add(RfcConfigParameters.Password, "yourpassword");
conf.Add(RfcConfigParameters.Client, "001");
}
return conf;
}
public bool ChangeEventsSupported()
{
return true;
}
public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged;
}
回答2:
I would prompt the user for the password in this case. I would use a dialog box that masks the text with a password character.
Dim value As String
value = InputBox("Security Check", " Enter password", "*")
objParameter.Add(RfcConfigParameters.Password, Convert.ToString(value))
来源:https://stackoverflow.com/questions/23442323/sap-hard-coded-logon-parameters-not-allowed-when-using-a-destination-configurati