How can I connect to SAP using sapnwrfc library?

5

Our software is written in C# and needs to connect to SAP. As some of our customers use older versions of SAP, and others don't have SAP PI, we can't connect through webservices.

I tried to connect to SAP through the SAP NetWeaver Remote Function Call Library (sapnwrfc.dll) as follows:

  • Add sapnwrfc.dll and the other dlls from NWRFC_6-20004550.SAR (being icudt34.dll, icuin34.dll, icuuc34.dll, libicudecnumber.dll, and libsapucum.dll) to C:\WINDOWS\system32, to be sure that they can be found.
  • In my C# code add the following in the class definition:
        [DllImport("sapnwrfc.dll", CharSet = CharSet.Auto)]
        public static extern void RfcInit();
    and the following in the method that should do the work:
        RfcInit();

Running this code gives a DllNotFoundException:
Unable to load DLL 'sapnwrfc.dll': This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)

Running the standard connect-to-C++-from-C# example
    [DllImport("user32.dll", CharSet = CharSet.Unicode)]
    public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);
    MessageBox(new IntPtr(0), "Hello World!", "Hello Dialog", 0);
works fine.

Any suggestions how to make this work fine (so that we don't need to workaround this problem by writing a Java proxy using JCo)?

c#
sap
dllnotfoundexception
saprfc
asked on Stack Overflow Feb 26, 2010 by Hendrik Jan van Randen • edited May 11, 2020 by Suncatcher

3 Answers

2

Did you check with the Dependency Viewer if you are missing some DLL? I did once write a managed wrapper for the rfc library (at least part of it) and I remember having a problem with some of the rfc libraries I downloaded. One version simply did not work and I did not figure out what was wrong. Another version (older) worked just fine.

I did however have problems with the unicode library (some memory access problem that appeared randomly) so I had to switch to the non-unicode version...

If I had to do something like this again, I would very seriously consider to buy a connector: http://www.theobald-software.com/en/products/erpconnect.htm

I cannot say if it is any good, but they seem to be around for a while now.

answered on Stack Overflow Feb 27, 2010 by Stefan Egli
2

Why don't you simply use SAP's ".NET Connector" (NCo3)? See SAP note 856863 for a link to the download page and documentation.

answered on Stack Overflow Mar 5, 2018 by Lanzelot
0

Please try to copy icudt34.dll, icuin34.dll, icuuc34.dll, libicudecnumber.dll, and libsapucum.dll to the directory of your project's bin. I had try it and it works well.

answered on Stack Overflow Sep 29, 2020 by wishfriday

User contributions licensed under CC BY-SA 3.0