Hi,
This job uses ActiveX Data Object to connect the external database and access the tables from the AX.
It uses the sql native client for the connection. Since CCADO class uses COM object so it is not possible to run on AX Server side batch but it can run on client side batch. To overcome this we can use ODBCConnection class this will run on server-side batch.
static void connectTo_EXT_DB(Args _args)
{
CCADOConnection connection = new CCADOConnection();
CCADOCommand ccADOCommand;
CCADORecordSet record;
COM recordSet;
str connectStr = "Driver={SQL Native Client};Trusted_Connection=no;SERVER=name;DATABASE=name;User Id='sql username';Password='password'";
;
try
{
connection.open(connectStr);
ccADOCommand = new CCADOCommand();
ccADOCommand.commandText("Select * from Emp");
ccADOCommand.activeConnection(connection);
record = ccADOCommand.execute();
recordSet = record.recordSet();
while (!record.EOF())
{
print record.fields().itemIdx(0).value();
recordSet.moveNext();
}
pause;
}
catch
{
error("An Exception has occurred");
}
connection.close();
}
Thanks,
K. Arunsubramaniam
No comments:
Post a Comment