Skip to main content

Posts

Showing posts with the label connections

Connecting to Databases through X++

In this article, I am going to explain about different ways through which one can connect to different databases for data manipulation operations. In AX, the methods that I know are following. Please feel free to add more methods that you feel are also available. ODBC Connection ADO Connection OleDB Connection Connection class Let us go through each of these options one by one. ODBC Connection: ODBC stands for Open Data Base Connectivity. It is a connection that is created to define a connection between a computer and a database stored on another system. The ODBC connection contains information needed to allow a computer user to access the information stored in a database that is not local to that computer. In Dynamics AX, we have ODBCConnection class to carry out this type of database connection need. This class uses LoginProperty class for login information and uses Statement and ResultSet classes for carrying out DML operations. Below is an example of how to use this cla...

Reading Data through SQL Data Reader in AX 2009

static void CheckDatabaseConThroughDotNet(Args _args) { System.Data.SqlClient.SqlConnection con; System.Data.SqlClient.SqlCommand com; System.Data.SqlClient.SqlDataAdapter da; System.Data.SqlClient.SqlDataReader dr; System.Data.DataSet ds; str _vendName; ; try { con = new System.Data.SqlClient.SqlConnection(strfmt("Data Source=Ibrahim; Initial Catalog=DynamicsAx; Integrated Security=true")); com = new System.Data.SqlClient.SqlCommand("Select * from VendTable",con); con.Open(); dr = com.ExecuteReader(); while(dr.Read()) { // _vendName = dr(0); } con.Close(); } Catch(Exception::Error) { info("error in Error Class"); } Catch(Exception::CLRError) { info(CLRInterop::getLastException().ToString()); } }

Executing direct SQL statements

Today I want to talk about executing SQL statements in X++ on both the AX database and external databases. This is something probably every AX developer will have to do at some point. You’ll want to do this for many reasons; to execute stored procedures, to improve performance, to get data from an external database, and so on. I will provide samples for two classes: - Connection (Execute SQL statement on current AX database) - ODBCConnection (Execute SQL statement on external database) I will not cover the ADO connection (CCADOConnection class), because it doesn’t work when you run it on server (or in batch), and I don’t like that. If you do, try to convince me ;-). Executing direct SQL on the current AX database When you execute a SQL statement, there are two options: - either you did a select and you expect a result to be returned - or you did insert/update/delete and you don’t expect a result. The first sample is for a SQL statement that returns a result: public static serve...