Dynamics AX 2012 Business Connector logon from VB.NET

Posted on 2011-10-14
Last Modified: 2012-05-12
I'm trying to log on to AX 2012 using Business Connector, but I'm getting an error.

I have added the reference to the Microsoft.Dynamics.BusinessConnectorNet.dll

Here's the code:
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Imports BC = Microsoft.Dynamics.BusinessConnectorNet

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim strTemp As String = ""

  Dim AXapta As BC.Axapta
  Dim custTable As BC.AxaptaRecord
  Dim bcProxyCredentials As System.Net.NetworkCredential
    AXapta = New BC.Axapta
    bcProxyCredentials = New System.Net.NetworkCredential("axbc", "password", "ourdomain.local")
    AXapta.LogonAs("axbc", "ourdomain.local", bcProxyCredentials, "CEU", "en-us", "", "TESTAX")
    'AXapta.Logon("", "", "", "")
  Catch ex As System.Exception
  End Try

End Sub
End Class

Here's the error:

System.IO.FileLoadException: A procedure imported by 'Microsoft.Dynamics.AX.ManagedInteropCore32.dll' could not be loaded.
File name: 'Microsoft.Dynamics.AX.ManagedInteropCore32.dll'
   at Microsoft.Dynamics.BusinessConnectorNet.Axapta.LogonAs(String user, String domain, NetworkCredential bcProxyCredentials, String company, String language, String objectServer, String configuration)
   at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\c\AX\Development\VB\BCTester\BCTester\Form1.vb:line 42


axbc user is:
part of ourdomain (active directory)
has the roles: BusinessConnector and System Administrator set up in AX 2012

I'm using Visual Basic Express 2010 with target set to Net 4.0.
Windows XP PRO SP3
Question by:ETdude
    LVL 6

    Expert Comment

    -How did you install the Business Connector ?
    -I recommend to run the same code on Windows 7 PC, you might find it works ok (due to support for new security protocols that are not supported on XP)
    -Try to use .NET 3.5 instead of .NET 4

    Author Comment

    I didn't personally install it. It was done by a partner. We have set up a proxy user with BusinessConenctor role.

    I have tried to switch to 3.5, but I'm getting the same error. Microsoft suggested to use 4.0 as the target.

    I think I have found a culprit. Microsoft.Dynamics.AX.ManagedInteropCore32.dll is calling some functions from advapi32.dll that are shown in red when using dependency walker.
    These are functions: EnableTraceEx, EventRegister, EventUnregister, EventWrite.
    I'm using the latest version 5.1.2600.5512 of advapi32.dll that came with Service Pack 3 for XP.

    Finally I have tried the same code on Windows 7 machine and it worked right away. I wish I could develop on XP Pro though.
    LVL 6

    Expert Comment

    Hello ETdude,

    Based on your findings which indicate that the Business Connector works fine on your Win 7 but not on Win XP and my past experience with integrating with Dynamics AX, I recommend to use the AX AIF (Application Integration Framework).
    This approach is the one recommended by Microsoft -

    When using AIF (requires separate AX license on server side), you can access AX from clients using WCF and MSMQ. I recommend to use AIF WCF Services. Developing .NET WCF client code can be done on your Windows XP SP3.
    Refer to Microsoft AX documentation at which includes details and sample C# code (you can use VB.NET as well).

    Good luck

    Author Comment

    Do you now if I can access the AX services using VB6?
    We have a lot of integration I have developed using VB6 for our current ERP (we will switch to AX next year) and would be happy not to convert them all to
    LVL 6

    Accepted Solution

    You can communicate between VB6 and AX AIF "File system exchange" adaptor using XML files.
    Refer to Microsoft Dynamics AX AIF configuration white paper

    Author Comment

    It's a general advice without specifics and the most difficult part is to know details.
    LVL 6

    Expert Comment

    I am realy surprised. You could have asked for more details instead of closing the question with such low rating.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Automatically creating a Trello card using data from a Microsoft Dynamics CRM record turned out to be an easy project that yielded great results.  Here's how I did this for an internal team at General Code.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now