How to make a DI-API Connection – “The right way”…
One of the first thing you learn when you learn the SAP Business One SDK is how to make a DI-API. But if you learned this many years ago and never look at the recent samples in the SDK Help I will claim there is a good chance that you are doing it ”wrong”.
Let’s have a closer look at the DI-API connection properties.
On the Company object we have the following 10 Properties dealing with the connection:
So since there are 10 Properties you might think you need to set all 10 of them, but this is not true. You actually only need to set the first 5 of them (6 if you want the error messages in other languages than English)… rest are not needed and are only there for backward compatibility.
OK, you might already know this but you are setting the rest “just in case”… well, that is actually a really bad idea and here is why.
The first reason off cause is you might by mistake set one of the properties wrong leading to a connection error, but even if everything is set correct there are actually bad side-effects.
Let’s see a sample of that:
If everything is right you will of cause get a result back of 0 (no error code).
But let us explore a scenario where the user “TEST” is locked
With our above code, we get this good error message telling us what is wrong:
Lets now explore the same issue in a scenario where you set the DbUsername and DbPassword in addition to the above code (or some of the other fields like many people do out there because of the “more is better mentality”)
Well, “more is not better”, is actually worse despite the data being right. Here is the result:
Gone are the nice clear error message of “User is Locked” and are replaced with the generic and frankly rather unhelpful -4008 error code “Login SLD Fail, make sure the Server, Company and user Credentials are correct” … Good luck finding that the real issue is actually a locked user!
So when you do DI-API Connections “less is better”
But wait: How can I be sure you are correct?
Well, just have a simple look at the DTW Login Screen from SAP
It has exactly the 6 mentioned properties, meaning if they do not ask for more so shouldn’t you!
If you want in general to learn more about the different DI-API Error codes and what they mean, this is a great resource on how to troubleshoot
Dear Rasmus Wulff Jensen,
Is it possible to use SAP DI APIs in Collibra, can you please help me in this scenario.
We have a requirement for this,
Sorry, I do not know Collibra so no idea if it can make DI-API connections, but in general, a system making a DI-API connection need to be Microsoft Windows-based and can work with COM Objects (as DI-API is a COM object). If that is not the case in Collibra then I guess it is not possible
I am receiving this error while trying to login with DI server api.
<?xml version="1.0"?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
Can anyone guide why this is appearing?
Hello, thanks for your explanation.
That being said, this doesn't work for me...
Following your instruction of only using these attributes:
LastErrorDescription responds with:
Failed to connect SLD, make sure SLD server is correct and available
For the property server would you recommend using the server name as displayed in control center of System Landscape Directory.
When I also provide DbUserName, DbPassword, and LicenseServer.
The connection is succesful.