on 07-27-2009 1:07 PM
Hi, All !
I'm trying to connect to R3 from C# asp.net application and using wdtlog.ocx. Here is my source code:
using SAPLogonCtrl;
public partial class _Default : System.Web.UI.Page
{
protected SAPLogonControl SAPLogOnControl1;
public static Connection connection;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SAPLogonControl SAPLogOnControl1 = new SAPLogonControl();
connection = (Connection)SAPLogOnControl1.NewConnection();
connection.System = "SSS";
connection.User = "UUU";
connection.Password = "ppp";
connection.SystemNumber = 1;
connection.Client = "100";
connection.Language = "uk";
connection.ApplicationServer = "10.10.10.10";
connection.SAPRouter = "/H/192.168.192.168/H/";
if (connection.Logon(0, true))
{
Label1.Text = "Logon O.K.";
}
else
{
Label1.Text = "Error on Logon :-(((";
}
}
When I'm trying to set any "connection" objects property I get an AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I can't find any examples for C#.
Help me, please.
Thanks.
Kucher.
This works for me......
SAPLogonCtrl.SAPLogonControlClass SapLogonControl = new SAPLogonCtrl.SAPLogonControlClass();
SAPLogonCtrl.Connection SapConnection = null;
SAPFunctionsOCX.SAPFunctionsClass SapFunctions = new SAPFunctionsOCX.SAPFunctionsClass();
SAPFunctionsOCX.Function SapFunctionInterface = null;
...
private bool LogOn()
{
bool Success = true;
try
{
PrintLine("Connecting to {0}-{1}...", SapSystem, SapClient);
if (SapConnection != null)
{
if (SapConnection.IsConnected == SAPLogonCtrl.CRfcConnectionStatus.tloRfcConnected)
{
PrintLine("Skipping logon... Already connected!");
return Success;
}
}
SapLogonControl.TraceLevel = 3;
SapLogonControl.Client = SapClient;
SapLogonControl.User = SapUser;
SapLogonControl.Password = SapPassword;
SapLogonControl.Language = SapLanguage;
SapLogonControl.System = SapSystem;
SapLogonControl.SystemNumber = SapSystemNumber;
SapLogonControl.ApplicationServer = SapApplicationServer;
SapConnection = (SAPLogonCtrl.Connection)SapLogonControl.NewConnection();
if (SapConnection.Logon(0, true))
{
PrintLine("Connected to SAP");
}
else
{
Success = false;
PrintLine("Failed to connected to SAP!");
}
}
catch (Exception x)
{
Success = false;
PrintLine(x.ToString());
}
return Success;
}
private bool TestClick()
{
try
{
if (!LogOn())
return false;
SapFunctions.Connection = SapConnection;
SapFunctionInterface = (SAPFunctionsOCX.Function)SapFunctions.Add("Z_DATE_CONVERT_TO_STRING");
SAPFunctionsOCX.Parameter TestDate = (SAPFunctionsOCX.Parameter)SapFunctionInterface.get_Exports("DATE");
string TestDateStr = "2010-01-09";
TestDate._Value = TestDateStr;
PrintLine("Sending test date \"{0}\" to BAPI", TestDateStr);
SapFunctionInterface.Call();
if (SapFunctionInterface.ReturnCode == SAPFunctionsOCX.RFC_RC.RFC_OK)
{
}
SAPFunctionsOCX.Parameter test = (SAPFunctionsOCX.Parameter)SapFunctionInterface.get_Imports("SDATE");
string ResultDate = test._Value.ToString();
PrintLine("Output from BAPI: {0}", ResultDate);
}
catch (Exception x)
{
PrintLine(x.ToString());
LogOff();
return false;
}
LogOff();
return true;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kucher,
what is the release of the SAP system you want to connect to.
If it is based on SAP NetWeaver 6.20 or higher you can publish RFC function modules as web services.
Then you would be able to proceed as described in the following article:
Though it describes the special case of state oriented communication it especially describes how to publish a RFC function module as web service and the consumption using Visual Studio.
Best regards,
André
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
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.