简体   繁体   中英

Can you use Visual Studio 2017 with the SAP .NET Connector 3.0?

I'm currently working on a RFC connection between Visual Studio 2017 and a SAP Server hosted on Linux(openSUSE) on a VirtualBox. The only posts I found about this problem are very old and not helpful. I want to create a RFC Function in C# that returns the data of the database in a chart, but I have no clue how to start with the code and how to setup the connection between my visual studio and the sap server. I hope someone can help me with these problems.

If you have no clue how to start, then why not first having a look into the NCo documentation? You can download it from https://support.sap.com/nco .

Since your environment does not seem to be limited to Windows only, I would also think about if the .NET environment is the best choice for your project? You will get better OS portability options if using other connectors. You will find the SAP connectors for other environments and programming languages at https://support.sap.com/connectors .

Can you use Visual Studio 2017 with the SAP .NET Connector 3.0?

The straight answer to the high level question in the title is yes you can. I'm myself using Visual Studio 2017 at the moment to develop a web service based on current NCo 3.

I'm currently working on a RFC connection between Visual Studio 2017 and a SAP Server hosted on Linux(openSUSE) on a VirtualBox.

That is a bit confusing - are you really intending to connect VS itself to SAP, or are you rather writing an application with VS, that application which will connect to SAP? .NCo is agnostic of the hosting environment of SAP. I've used it to connect to Linux based SAP, Windows based SAP, it makes no difference.

I want to create a RFC Function in C# that returns the data of the database in a chart

RFCs are Remote Function Call to SAP's FM Function Modules. SAP FMs are programmed in the ABAP language only. BUT .NCo allows to implement an RFC Server interface in front of .Net code (such as C#) so that you can call from SAP as an RFC call the C# code running in the RFC server that is your application. There's an example of that in the .NCo public documentation.

Which database are you trying to read? SAP's? You are not supposed to read the SAP database directly from external code, rather you are supposed to use the ABAP written RFCs running on the SAP system to access the data. While there is an RFC to read raw table, it is frowned upon by SAP to use it as it by-passes everything from security to object model. SAP administrators sometimes will ban than RFC from running on their system. Instead you should use regular RFCs, BAPIs or IDOCs from the ALE to access the SAP data.

More simply, .NCo allows to call from .Net code to SAP to execute RFCs. This is the basic scenario you should likely start with to get familiar with the NCo library.

Declare the following SAP details in you web.config / app.config

 <add key="DestinationName" value="*ANYNAME*" />
    <add key="AppServer" value="****" />
    <add key="SystemNumber" value="**" />
    <add key="SystemID" value="**" />
    <add key="UserName" value="***" />
    <add key="Password" value="***" />
    <add key="Client" value="***" />
    <add key="Language" value="EN" /> 

Download appropriate connector dlls (sapnco.dll and sapnco_utils ) from SAP site and refer them in your application. Refer the sample code below for rest of the stuff

                RfcConfigParameters para = new RfcConfigParameters();
                para.Add(RfcConfigParameters.Name, destinationname);
                para.Add(RfcConfigParameters.AppServerHost, appServer); // If they are using SAP Router then please refer SAP documentation on Public and PrivateIP address details as you need both
                para.Add(RfcConfigParameters.SystemNumber, systemNumber);
                para.Add(RfcConfigParameters.SystemID, systemID);
                para.Add(RfcConfigParameters.User, user);// "RFCUSER"); 
                para.Add(RfcConfigParameters.Password, password);
                para.Add(RfcConfigParameters.Client, client);
                para.Add(RfcConfigParameters.Language, language);// "EN");
                RfcDestination dest = RfcDestinationManager.GetDestination(para);

                // Test connection
                dest.Ping();

                RfcSessionManager.BeginContext(dest);
                var rfcFunction = dest.Repository.CreateFunction("RFCFunctionName");
                rfcFunction.SetValue("INPUT PARAMETER NAME", "Value");
                // Call the function
                rfcFunction.Invoke(dest);

For further details refer the documentation below: https://support.sap.com/content/dam/support/en_us/library/ssp/products/connectors/msnet/dotnet_connector_30_programming_guide.pdf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM