huysentruitw / SapNwRfc

SAP NetWeaver RFC library for .NET 5, .NET Core and .NET Framework
MIT License
148 stars 43 forks source link

How to resolve ISapConnectionPool in .Net Core 3.1? #11

Closed p3nj closed 4 years ago

p3nj commented 4 years ago

Hi, been using this project for sometime with console application, thank you for your work! after awhile using console application I decide to brings RFC into my WebAPI, but when I register ISapConnectionPool and try to resolve it, seems like it doesn't have active connection to use.

here is my Register file, image

my ConfigureServices, image

and here is where I try to resolve a connection from pool, image

as you can see there seems like no _connection I can use, so application just hang there and close itself.

my connection string is same as README.md file "AppServerHost=MY_SERVER_HOST; SystemNumber=00; User=MY_SAP_USER; Password=SECRET; Client=100; Language=EN; PoolSize=5; Trace=8";

my WebAPI is using UnitOfWork structure, but I think that's not too relatived with the problem I had above.

Thanks.

IAmWhoAmI007 commented 4 years ago

Hi, I also used this some time ago, and I also encountered this problem. I finally got the connection directly in the function. like this

var connectionString = "AppServerHost=MY_SERVER_HOST; SystemNumber=00; User=MY_SAP_USER; Password=SECRET; Client=100; Language=EN; PoolSize=5; Trace=8;";
var connection = new SapConnection(connectionString);
connection.Connect();
var someFunction = connection.CreateFunction("FuncName");
var result = someFunction.Invoke<OutputObject>(new InputObject { KeyDate = DateTime.Today });
someFunction.Dispose();
connection.Dispose();

I hope it can help you, but there is a problem with this. Every time you call the SAP interface, a .trc file will be generated, which will make the directory confusing. Currently, we can only clean it up with a scheduled task. I don't know what a good way. image

huysentruitw commented 4 years ago

@limeless A connection is only taken from the pool when InvokeFunction is being called. So in your screenshot, it is normal that at that point, there's no connection. Do you get any exception when calling the InvokeFunction ?

@IAmWhoAmI007 this is good for non DI environments like console applications, but not for DI driven projects like ASP.NET Core projects. As for the .trc files, these can be excluded as mentioned in https://github.com/huysentruitw/SapNwRfc/issues/9#issuecomment-671859253

huysentruitw commented 4 years ago

You say you're using the same connection string as in the README. Stupid question perhaps, but you did replace the server, user and password with the correct information, right? Otherwise that could explain why calling InvokeFunction hangs (as it can't connect to the SAP server). Anyway, it shouldn't crash your application. If you can give me any stack-trace, that would be very helpful.

p3nj commented 4 years ago

Hi @huysentruitw

.... Do you get any exception when calling the InvokeFunction ?

Sadly no, application quits itself without any exception, even with try-catch block.

You say you're using the same connection string as in the README. Stupid question perhaps, but you did replace the server, user and password with the correct information, right? Otherwise that could explain why calling InvokeFunction hangs (as it can't connect to the SAP server). Anyway, it shouldn't crash your application. If you can give me any stack-trace, that would be very helpful.

Yes I did it with README format, also straight copy-paste the connection string from my console application ;)) Here is my stack-trace screen farthest I can get. image

Hope this help. thanks!

huysentruitw commented 4 years ago

@limeless can you call SapLibrary.EnsureLibraryPresent() somewhere at startup to make sure the libraries are found? Also check the eventlog of windows, it might contain more information about the crash.

Are you running your project with IIS Express or with Kestrel?

p3nj commented 4 years ago

@limeless can you call SapLibrary.EnsureLibraryPresent() somewhere at startup to make sure the libraries are found? Also check the eventlog of windows, it might contain more information about the crash.

Are you running your project with IIS Express or with Kestrel?

Sorry for the late reply, Im currently out of town. I do check event viewer but there's no RFC related error during debug,

I'm running my project via set csproj as Console Application, I believe is Kestrel? The deploy environment is going to be on Azure Registry Container. I will get back to you ASAP when I'm back to office. Thanks.

p3nj commented 4 years ago

@limeless can you call SapLibrary.EnsureLibraryPresent() somewhere at startup to make sure the libraries are found? Also check the eventlog of windows, it might contain more information about the crash.

Are you running your project with IIS Express or with Kestrel?

Hi @huysentruitw, the application is using Kestrel, I've put SapLibrary.EnsureLibraryPresent() inside my SAP RFC Register still no luck, also double checked EventViewer there's no related message about the crash... :<

p3nj commented 4 years ago

Hi @huysentruitw, Finally I was able to see the message from dotnet run at terminal, error message is like below

Could not open the ICU common library.
   The following files must be in the path described by
   the environment variable "PATH":
   icuuc50.dll, icudt50.dll, icuin50.dll [D:/depot/bas/753_REL/src/flat/nlsui0.c 1529] pid = 21796

PATH is currently set to .... *delete for very long PATH value*

[D:/depot/bas/753_REL/src/flat/nlsui0.c 1532] pid = 21796
Set the environment variable NLSUI_INIT_TRACE_LEVEL to 'high' to see more details. [D:/depot/bas/753_REL/src/flat/nlsui0.c 1541] pid = 21796
Check also SAP note 519753. [D:/depot/bas/753_REL/src/flat/nlsui0.c 1542] pid = 21796

After I put those dll into my C:\Windows folder, RFC works perfectly, Thanks for the help!!

huysentruitw commented 4 years ago

Fantastic news 🎉 !

That's why I added that very verbose error message to the SapLibrary.EnsureLibraryPresent(). It really helps pointing users to this very common problem. Glad you got it solved.