Dynamics AX with .Net framework
The Microsoft Dynamics AX compiler is compatible with the .Net framework and allows us to call .NET assemblies from Dynamics AX without rewriting the code. Most of the .NET system classes are referenced with standard AX, but we can also reference our own .Net assemblies with AX application. This is possible through the Appliation Object Treet (AOT) and the reference function. (AOT –> Reference)
Here are some examples that depict the use of .Net namespaces in Dynamics AX.
=> Oracle database connection -> We can execute an Oracle query in AX using “System.Data.OracleClient” namespace.
System.Data.OracleClient.OracleConnection connection;
System.Data.OracleClient.OracleCommand command;
System.Data.OracleClient.OracleDataReader dataReader;
str connStr ;
str query ;
;
//Connection string
connStr = "Server= OracleServer;User ID=Username;Password=Password”;
//Query to execute
query = “Select * from —“;
//Inter operational permission
new InteropPermission(InteropKind::ClrInterop).assert();
//Open DB connection
connection = new System.Data.OracleClient.OracleConnection(connStr);
connection.Open();
//Execute query
Command = new System.Data.OracleClient.OracleCommand(query, connection);
dataReader = comm.ExecuteReader();
//Read the result
while(dataReader.Read())
{
…
}
//Close connection
dataReader.Close();
connection.Close();
CodeAccessPermission::revertAssert();
=> Authenticate user in active directory/domain/machine
System.DirectoryServices.AccountManagement.ContextType ct;
System.DirectoryServices.AccountManagement.PrincipalContext pc;
;
ct = System.DirectoryServices.AccountManagement.ContextType::Domain;
pc = new System.DirectoryServices.AccountManagement.PrincipalContext(ct);
pc.ValidateCredentials(_username,_password);
This post is written by Gopi Balakrishnan. Gopi is a Senior Technical Analyst in the Microsoft Dynamics AX Practice at Ignify . Ignify is a Global Microsoft Dynamics Inner Circle Partner specializing in Dynamics AX for Retail, Distribution, Manufacturing and Chemicals verticals. For help on Microsoft Dynamics ERP email us at dynamics@ignify.com