Export (0) Print
Expand All

How to: Connect to Microsoft Dynamics AX Using the LogonAs Method

You can use the LogonAs method to connect to Microsoft Dynamics AX to implement a customized .NET-connected application. This example uses the LogonAs method to connect to the AOS using a specified proxy user account.

In this section, you will ensure that the AOS status is Started.

To start the AOS

  1. Click the Start menu, point at Administrative Tools, and then select Services.

  2. In the Services window, in the right pane find the AOS, the default install name is Dynamics Server$1-Company1. Check the Status, it should be Started. If not, right-click Dynamics Server$1-Company1 and then click Start.

This example assumes that you have created a user to set up as a proxy user or you will use your own user ID, domain, and password. Microsoft Dynamics AX is not supported to run without a domain controller. In this section you will set up the proxy user.

To set up the proxy user

  1. From the navigation pane, select Administration, expand the Setup node, expand the Security node, and then select Business Connector Proxy.

  2. Enter the same user ID credentials that you will specify in the code. Fill in the alias with the user ID and the network domain that has a fully qualified domain name that the user ID is a part of.

In this section, you will create a Windows application that will access data in Microsoft Dynamics AX.

To create a project

  1. Open Visual Studio.

  2. From the File menu, click New, and then click Project to display the New Project dialog box.

  3. In the Project types pane, select Visual C#. In the Templates pane, select Windows Application.

  4. Set the name to LogonAsExample.

  5. To change the location of the solution directory, select Browse and specify a new location.

  6. Click OK.

Once you have created LogonAsExample, you can add controls to the form by dragging them from the toolbox. In this example, you will add a button to the form which will be used to log on to Microsoft Dynamics AX.

To create the layout a form

  • In the Toolbox, select the Button control, and then add it to the form.

To logon to Microsoft Dynamics AX, you must create a connection using .NET Business Connector. In this section, you will add a reference to the .NET Business Connector.

To add a reference to .NET Business Connector

  1. In Solution Explorer, right-click References, and then select Add Reference.

  2. In the Add Reference window, select the Browse tab.

  3. Specify the location of Microsoft.Dynamics.BusinessConnectorNet.dll, and then click Add.


    For a typical install, assemblies are located at C:\Program Files\Microsoft Dynamics AX\40\Client\Bin\.

  4. Click OK.

In this section, you will use the LogonAs method to connect to Microsoft Dynamics AX on behalf of a specific user. This example specifies the proxy user. You will use a hard-coded string for the ProxyUserID and password that match the proxy that you specified in the Business Connector proxy.

To add code behind the form

  1. On the form, double-click button1 to access the LogonAsExample.Form1 code.

  2. Add the following using statement to the LogonAsExample.Form1 form.

    using Microsoft.Dynamics.BusinessConnectorNet;
  3. Add the following code on the click event of the button control.

    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.
            DynAx.LogonAs(strUserName.Trim(), "", nc, "", "", "", "");
            MessageBox.Show("Logoff completed.");
        catch (Exception ex)
  4. Press F5 to run the application.

  5. On the form, click button1. The message box displays Success. Click OK. The message box displays Logoff completed.

For more examples and information, see the LogonAs method reference content.

Community Additions

© 2015 Microsoft