Pages

September 09, 2013

Connecting to Databases through X++ PART -I

Connecting to Databases through X++ PART -I






In This series of post we will discuss about all possible ways through which we can connect to different databases.

     1.    ODBC Connection (Open Data Base Connection)
     2.    ADO Connection (ActiveX Data Objects)
      3. OLEDB Connection (Object Linking and Embedding, Database)
      4. Connection class

    1.  ODBC Connection:

ODBC used to define a connection between a computer and a database stored on another system. The ODBC connection allows 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 further uses LoginProperty class for login information and uses Statement and ResultSet classes for carrying out DML operations.
Here is an example of how to use this class.

static void theAxapta_ODBCConnection(Args _args)
{
    LoginProperty   loginProp;
    ODBCConnection  conn;
    Resultset       resultSet, resultSetCount;
    Statement       statement1, statement2;
    ;
    loginProp = new LoginProperty();
    loginProp.setServer(‘theAxapta’);//you can use IP address as well
    loginProp.setDatabase(‘AXDEVDB
);
    conn = new ODBCConnection(loginProp);
    statement1  = conn.createStatement();
    resultSet   = statement1.executeQuery("SELECT * from CustTable where DATAAREAID = ‘CEU’");
    while (resultSet.next())
    {
        info(resultSet.getString(1));
    }
}


Other related posts:



-Harry

No comments:

Post a Comment

Thanks