on 04-15-2014 1:25 PM
Good Day.
I'm trying to develop an application that connects to SAP using the .net connecter 3. I'm getting different users randomly picking up incorrect user, Probably about 2 percent is getting incorrect connections. The application is used by multiple users concurrently and the users have shared connections (e.g 10 users use the same connection as they are in that business unit.). Currently there are about 3-4 SAP calls per second from different locations and users.
Could someone send me a quick sample of how they would create destinations for multiple users connecting to SAP using .net connector 3?
That would be greatly appreciated.
Thanks
Hi Lesego,
perhaps you first clarify what you are doing at the moment. This is not clear from your current text. Without more details it's impossible to tell what you should do differently.
Best regards,
Markus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Markus.
I'm have my code listed below:
I have about 130 different connections that can be created. There are a lot more users that access these connections when they want to access SAP. This happens concurrently. I have changed my code to custom destinations from just getting connections using RfcDestinationManager.GetDestination("OneMobile"); but i randomly get a user who picks up connection C921 when they requesting/getting C934. I was asking if someone can help me with the simplest code to getting a connection (with multiple concurrent users in mind) and i can compare and fix my so that i get the correct connection 100percent of the time.
private static RfcDestination GetSapRfcDestination(string authTicket, out RfcRepository sapRfcRepository, ref string message)
{
try
{
AuthenticationTicket authenticationTicket;
if (string.IsNullOrEmpty(authTicket))
authenticationTicket = new AuthenticationTicket();
else
authenticationTicket = new AuthenticationTicket(authTicket);
if (_sapDestinationManager == null)
{
_sapDestinationManager = new SapDestinationManager();
RfcDestinationManager.RegisterDestinationConfiguration(_sapDestinationManager);
}
if (authenticationTicket.UserName == null)
{
RfcDestination destination = RfcDestinationManager.GetDestination("OneMobile");
sapRfcRepository = destination.Repository;
message = "Login Successful";
Log.Trace("One Mobile connection: " + destination.Repository.ToString());
return destination;
}
else
{
_sapDestinationManager.Username = authenticationTicket.UserName;
_sapDestinationManager.Password = authenticationTicket.Password;
RfcDestination destination = RfcDestinationManager.GetDestination("OneMobile");
#region Custom Destination
RfcCustomDestination customDestination = destination.CreateCustomDestination();
customDestination.User = authenticationTicket.UserName;
customDestination.Password = authenticationTicket.Password;
if (customDestination.SystemAttributes.Destination == null)
{
_sapDestinationManager = null;
message = "Name or password is incorrect";
sapRfcRepository = null;
return null;
}
else
{
sapRfcRepository = customDestination.Repository;
message = "Login Successful";
}
Log.Trace("CTM: " + customDestination.Repository.ToString());
return customDestination;
#endregion
}
}
catch (Exception exception)
{
if (exception.Message.Contains("Name or password is incorrect"))
{
message = Message.NameOrPasswordIsIncorrect;
}
else
message = exception.Message;
Log.ErrorException("Error on calling SapDestination call", exception);
}
sapRfcRepository = null;
return null;
}
Hi Lesego,
your coding reminded me of the fact that I already saw this code in some other thread. Just like I replied in the other thread that you hijacked:
actually, your code should be different:
* Do not regularly resgister/unregister an instance of IDestinationConfiguration. Unregistering this is only needed in very rare cases. Registering the IDestinationConfiguration should be done once in the lifetime of the process - in 99% of the use cases this is the fitting approach
* Using CustomDestination like done by you is ok, but if the logon fails, you don't have to unregister the IDestinationConfiguration. Actually, in your current code you even haven't checked so far whether logon is possible. Only a Ping will do so.
* assigning "Name or password is incorrect" to a variable named success looks strange to me ...
Doing it the way you do it will very likely leave to the observed behavior.
Best regards,
Markus
Hi Lesogo,
I'm rewriting your code here by hand, so you need to check and adjust the syntax yourself.
void main(void) { // or what ever is your application startup method
// register destination manager once at startup ....
SapDestinationManager _sapDestinationManager = new SapDestinationManager();
RfcDestinationManager.RegisterDestinationConfiguration(_sapDestinationManager);
test_destination("user1", "password1");
test_destination("user2", "password2");
}
private static RfcDestination GetSapRfcDestination(string username, string password)
{
RfcDestination destination = RfcDestinationManager.GetDestination("OneMobile");
if (destionation != null) {
RfcCustomDestination customDestination = destination.CreateCustomDestination();
customDestination.User = username;
customDestination.Password = password;
return customDestination;
}
return null;
}
private static test_destination(string username, string password) {
RfcDestination destination = GetSapRfcDestination(username, password);
try {
destination.Ping(); // you get an exception on logon failure here
}
catch(Exception ex) {
// TODO: handle your exception here.....
}
}
User | Count |
---|---|
84 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.