关闭用户会话AXAPTA

问题描述 投票:0回答:1

使使用Dynamics AX商务连接器连接AX的网站正常运行,但有时用户未注销。

这是我的代码:

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();
        }

并且在斧头中,我可以看到用户登录。有时再次发生这种情况,这就是为什么我不知道可能是谁的原因。也许Dispose()方法更好?。

感谢您抽出宝贵的时间阅读本文档。

asp.net axapta x++
1个回答
2
投票

登录/注销对我来说是正确的,但是如果您说有时无效,则原因很可能是以下原因之一:

  • 该业务连接器可能是片状的。这不是Microsoft的优先事项,最终被折旧了。
  • //Execute some methods部分中发生的任何事情都可能锁定或阻止注销。
  • 您可能需要更新内核以获得业务连接器的更新版本

在我的AX2012R3环境中,我可以一次又一次地成功运行以下PowerShell代码。这将我引向上述原因之一。

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()

0
投票

尝试使用此代码,这是Microsoft参考,这里的链接(对我而言很好用)

https://docs.microsoft.com/en-us/dynamicsax-2012/developer/how-to-connect-to-microsoft-dynamics-ax-using-the-logonas-method

private void button1_Click(object sender, EventArgs e)
{
    // Create an instance of the Axapta class.
    Axapta DynAx = new Axapta();

    // Add the proxy user.
    // Replace the ProxyUserID and password parameters with the 
    // proxy user name and password that you specified
    // in the Business Connector Proxy.
    System.Net.NetworkCredential nc = new System.Net.NetworkCredential("ProxyUserID", "password");
    string strUserName = "ProxyUserID";

    // Test the connection to the .NET Business Connector.
    try
    {
        DynAx.LogonAs(strUserName.Trim(), "", nc, "", "", "", "");
        MessageBox.Show("Success");
        DynAx.Logoff();
        MessageBox.Show("Logoff completed.");

    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
        MessageBox.Show(ex.Message);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.