jonaChaz
jonaChaz

Reputation: 301

Close user sessions AXAPTA

im making a website who uses the Dynamics AX Business Connector to connect with AX, it´s working fine but sometimes the users don´t logout.

Here is my code:

Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
        try
        {
            DynAx.Logon(null, null, null, null);
            //Execute some methods
            DynAx.Logoff();
        }
        catch (Exception ex)
        {
            DynAx.Logoff();
        }

and in ax i can see the users logged in. Again this happens sometimes, thats why i don´t know who may be. Maybe Dispose() Method it's better?.

Thank you for taking your time to read this.

Upvotes: 0

Views: 717

Answers (1)

Alex Kwitny
Alex Kwitny

Reputation: 11564

Logon/logoff works for me correctly, but if you're saying sometimes it doesn't, then the reason is most likely one of the following:

  • The business connector can be flaky. It's wasn't a Microsoft priority and eventually was depreciated.
  • Whatever is happening in your //Execute some methods section could be locking or preventing the logoff.
  • You may need to update your kernel to get an updated version of the business connector

In my AX2012R3 environment I can run the below PowerShell code over and over with success. This points me towards one of the above as a cause.

Add-Type -Path "C:\Program Files\Microsoft Dynamics AX\60\BusinessConnector\Bin\Microsoft.Dynamics.BusinessConnectorNet.dll"
$ax = new-object Microsoft.Dynamics.BusinessConnectorNet.Axapta
 
$ax.logon($null, $null, $null, $null)
$b = $ax.CreateAxaptaRecord("userinfo")

$array = New-Object System.Collections.ArrayList
 
$b.ExecuteStmt("select id from %1")
while($b.found){
    $array.add($b.get_field("id")) | out-null
    $b.next() | out-null
}
 
$array | Format-Table -AutoSize

$ax.Logoff()
$ax.Dispose()

Upvotes: 2

Related Questions