onsdag 23 september 2009

BusinessConnectorTest

Warning! This note only makes sense for the Dynamics Ax developers out there. Specifically if you are setup up Enterprise Portal or something similar that uses the .Net Business Connector to connect to Ax.

A simple tool for verifying if you have a working Business Connector .Net setup.

Download it here. To run it you need the 13MB Microsoft.Dynamics.BusinessConnectorNet.dll, version 5.0.1 (2009, SP1) in the program directory.

Basically the code looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Dynamics.BusinessConnectorNet;

namespace BusinessConnectorTest
{
class Program
{
static void Main(string[] args)
{
try
{
Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
Microsoft.Dynamics.BusinessConnectorNet.AxaptaRecord DynRec;

DynAx.Logon(null, null, null, null);
Console.WriteLine("Logon successful!");

DynRec = DynAx.CreateAxaptaRecord("CustTable");
Console.WriteLine("Create record successful!");

DynRec.ExecuteStmt("select firstonly * from %1");
Console.WriteLine("Select successful!");
Console.WriteLine(string.Format("Recid: {0}", DynRec.get_Field("RECID")));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
}
}


Very simple, but still handy to have. The catch is the good part :). Gives you an idea of what is wrong.

This code uses the current user to logon. Use "runas" to change user.

Inga kommentarer:

Skicka en kommentar