Wednesday 5 September 2012

Working with external database.

Working with external database :-


In this example i will explain how to access external sqlserver database tables in ax .

Steps:

Before going to work with database we have to first create a DNS through which we access external database .to create dns follow these steps,
 1)Administration Tools-->Database(odbc)
2)Dsn-->add (which opens a wizard)-->select sqlserver-->finish
3)(opens another window consists of) referdatasource name : give any name let us it is AX
     a)description:AX
    b)server:(its your server name) to which you want to connect
   c)next,next,finish-->testdatasource -->test connection
This finishes DNS creation

step2:

create a new job as follows:

static void odbcTest(Args _args)
{
  odbcconnection odbc;
LoginProperty login;
Statement st;
ResultSet rt;
;
login=new LoginProperty();
login.setDSN("AX");
login.setDatabase("AX593");
odbc=new odbcconnection(login);
st=odbc.createstatement();
rt=st.executequery("select * from custtable");
while(rt.next())
{
 info(rt.getstring(1));//here 1-represents coloumn number
info(rt.getstring(2))
}
}
}

No comments:

Post a Comment