Ax business connector provides a maximum of 2000 simultaneous sessions (web users). However, the online users sometimes are more than the 2000 limit, forcing further connections to queue and wait for other sessions to end. To go around this, you can create multiple AOS and point to the same database. While connecting, chose an AOS randomly. In addition to that, load-balancing will come in handy. Below is a sample C# code that connects using the business connector. FEEL FREE TO SUGGEST SOME IMPROVEMENTS
public AXConnector()
{
this.axapter = new BCN.Axapta();
bool ErrorOccured = true;
int connectionNo;
RestartConnection:
connectionNo = new Random(DateTime.Now.Millisecond).Next(1, 4);
//1st trial
if (ErrorOccured && connectionNo==1)
{
try
{
aos = "AOS1@AXSERVER1:2712";
this.axapter.LogonAs(this.strUserName, domain,
new NetworkCredential(this.strUserName, this.password, domain),
company, "en-us", aos, "");
}
catch (Exception e)
{
ErrorOccured = true;
e.Data.Clear();
goto RestartConnection;
}
}
//2nd trial
if (ErrorOccured && connectionNo == 2)
{
ErrorOccured = false;
try
{
this.axapter = new BCN.Axapta();
aos = "AOS2@AXSERVER1:2713";
this.axapter.LogonAs(this.strUserName, domain,
new NetworkCredential(this.strUserName, this.password, domain),
company, "en-us", aos, "");
}
catch (Exception e)
{
ErrorOccured = true;
e.Data.Clear();
goto RestartConnection;
}
}
//3rd trial
if (ErrorOccured && connectionNo == 3)
{
ErrorOccured = false;
try
{
this.axapter = new BCN.Axapta();
aos = "AOS3@AXSERVER1:2714";
this.axapter.LogonAs(this.strUserName, domain,
new NetworkCredential(this.strUserName, this.password, domain),
company, "en-us", aos, "");
}
catch (Exception e)
{
ErrorOccured = true;
e.Data.Clear();
goto RestartConnection;
}
}
//4th trial
if (ErrorOccured && connectionNo == 4)
{
ErrorOccured = false;
try
{
this.axapter = new BCN.Axapta();
aos = "AOS4@AXSERVER1:2715";
this.axapter.LogonAs(this.strUserName, domain,
new NetworkCredential(this.strUserName, this.password, domain),
company, "en-us", aos, "");
}
catch (Exception e)
{
ErrorOccured = true;
e.Data.Clear();
goto RestartConnection;
}
}
}
public AXConnector()
{
this.axapter = new BCN.Axapta();
bool ErrorOccured = true;
int connectionNo;
RestartConnection:
connectionNo = new Random(DateTime.Now.Millisecond).Next(1, 4);
//1st trial
if (ErrorOccured && connectionNo==1)
{
try
{
aos = "AOS1@AXSERVER1:2712";
this.axapter.LogonAs(this.strUserName, domain,
new NetworkCredential(this.strUserName, this.password, domain),
company, "en-us", aos, "");
}
catch (Exception e)
{
ErrorOccured = true;
e.Data.Clear();
goto RestartConnection;
}
}
//2nd trial
if (ErrorOccured && connectionNo == 2)
{
ErrorOccured = false;
try
{
this.axapter = new BCN.Axapta();
aos = "AOS2@AXSERVER1:2713";
this.axapter.LogonAs(this.strUserName, domain,
new NetworkCredential(this.strUserName, this.password, domain),
company, "en-us", aos, "");
}
catch (Exception e)
{
ErrorOccured = true;
e.Data.Clear();
goto RestartConnection;
}
}
//3rd trial
if (ErrorOccured && connectionNo == 3)
{
ErrorOccured = false;
try
{
this.axapter = new BCN.Axapta();
aos = "AOS3@AXSERVER1:2714";
this.axapter.LogonAs(this.strUserName, domain,
new NetworkCredential(this.strUserName, this.password, domain),
company, "en-us", aos, "");
}
catch (Exception e)
{
ErrorOccured = true;
e.Data.Clear();
goto RestartConnection;
}
}
//4th trial
if (ErrorOccured && connectionNo == 4)
{
ErrorOccured = false;
try
{
this.axapter = new BCN.Axapta();
aos = "AOS4@AXSERVER1:2715";
this.axapter.LogonAs(this.strUserName, domain,
new NetworkCredential(this.strUserName, this.password, domain),
company, "en-us", aos, "");
}
catch (Exception e)
{
ErrorOccured = true;
e.Data.Clear();
goto RestartConnection;
}
}
}