cancel
Showing results for 
Search instead for 
Did you mean: 

sap login programmatically

Former Member
0 Kudos

I didn't use SAP Login form.

Instead of SAP Login form, I made codes to connect to SAP like below sources.

When I run it, it connects to SAP and get some data from SAP successfully.

But, the page makes an error and didn't show the binded data at datagrid.

Can you help me?

The error message is belows.

PS : When I didn't connect with SAP, and bind the datagrid to internal table, it works fine.

=================CODE=================

private void Button1_Click(object sender, System.EventArgs e)

{

// Declare parameters here

SAPProxy1 proxy = new SAPProxy1();

this.components = new System.ComponentModel.Container();

System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();

this.destination1 = new SAP.Connector.Destination(this.components);

//

// destination1

//

this.destination1.AppServerHost = ((string)(configurationAppSettings.GetValue("destination1.AppServerHost", typeof(string))));

this.destination1.SystemNumber = ((short)0);

this.destination1.Username = "RFCB2B";

this.destination1.Password = "SVCUSA";

this.destination1.Client = ((short)(160));

this.destination1.Language = "en";

try

{

SAP.Connector.SAPLoginProvider.OpenSAPConnection(this, destination1.ConnectionString, false);

proxy.Connection = SAP.Connector.SAPLoginProvider.GetSAPConnection(this);

// Call methods here

string strEsvc_Rfc_Ok = null;

ZWEBIF2 zBuffer = new ZWEBIF2();

zBuffer.Buffer = this.TextBox1.Text;

Input_Data = new ZWEBIF2Table();

Input_Data.Add(zBuffer);

proxy.Z_Web_Rfc_D3("WB_MODEL_SEARCH", "C310", "0001656428", "E", out strEsvc_Rfc_Ok, ref In_31, ref In_33,

ref In_39, ref In_81, ref In_82, ref In_83, ref Input_1000, ref Input_Data, ref Output_1000, ref zwebiF2Table1);

Console.Out.Write(zwebiF2Table1.Count);

Console.Out.Flush();

// Now update Data Bindings. On WinForms this will be automatic, on WebForms call the following line

this.DataBind();

}

catch(Exception ex)

{

Console.Out.Write(ex.ToString());

Console.Out.Flush();

// If SAPLoginProvider.GetSAPConnection(this) cannot get a connection, we might get an error. // Normally this can be ignored as it will automatically will force a relogon.

}

}

===================ERROR========================

Server Error in '/WebApplication3' Application.

-


The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested Url: /WebApplication3/default.aspx

-


Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

Accepted Solutions (1)

Accepted Solutions (1)

reiner_hille-doering
Active Contributor
0 Kudos

If you don't want to use a Login page, you shouldn't user SAPLoginProvider.OpenSAPConnection / SAPLoginProvider.GetSAPConnection. This classes to internally some redirect to other pages which causes 404 error.

Instead us Connection.GetConnection() (for NCo 2.0) or just "new SAPConnection().

In NCo 2.0 you can easily reach this by just dragging a Destination from Toolbox or the corresponsing Application Server icon from Server Explorer to your form. The Destination is already configured to take most settings from the Web.config file (see the cyan icons on the properties), so you don't need to write "configurationAppSettings.GetValue" by hand.

In NCo 2.0 you can also drag the SAPProxy1 instance from the toolbox and wire the connection between it and the destination in designer.

Answers (0)