B1SLayer
B1SLayer copied to clipboard
Connection using different SAP users, not defined in Program.cs
Hi,
I need to connect to SAP with several users.
Is there a way to provide user and password when the service is running and not in Program.cs?
Thank you in advance.
Hi, @riccardopasqualetti.
In case you need to connect to multiple databases or use multiple users, you will have to create and manage multiple SLConnection
objects in your application and use the appropriate one when performing your requests.
A simple way to achieve this would be by creating a Dictionary
containing your connection objects and a key to uniquely identify each one.
var connections = new Dictionary<string, SLConnection>()
{
{ "myKey1", new SLConnection("https://localhost:50000/b1s/v1/", "SBO_COMPANY", "user1", "password") },
{ "myKey2", new SLConnection("https://localhost:50000/b1s/v1/", "SBO_COMPANY", "user2", "password") },
...
}
Then, you could perform requests directly from the Dictionary
by specifying the key:
var businessPartners = await connections["myKey1"].Request("BusinessPartners").GetAsync();
Anyway, this is just a suggestion and there are multiple ways you could implement this to best suit your scenario.
Let me know if this helps.