web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

error While Executing direct SQL on an external database using ODBC

(0) ShareShare
ReportReport
Posted on by 371

firstly i make a table in sql and want to know the table data through info 

so for that i write the job..but every time i run this job it shows the 3 error...

1) 

ODBC operation failed.
Unable to log on to the database.

2) [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application

3) Object 'OdbcConnection' could not be created..

static void sqlstatement1(Args _args)
{


OdbcConnection Connection;
LoginProperty loginprop;
SqlStatementExecutePermission Permission ;
Statement stmt;
ResultSet result;
str Dsn,UID,PWD,connectionstring,sqlstmt;
;

Dsn="datasource";
UID="";
PWD="";
connectionstring=strfmt("Dsn=%1;UID=%2;PWD=%3",Dsn,UID,PWD);
loginprop=new LoginProperty();
loginprop.setOther(connectionstring);
Connection=new OdbcConnection(loginprop);
sqlstmt="select * from Employees";
Permission=new SqlStatementExecutePermission(sqlstmt);
Permission.assert();
stmt=Connection.createStatement();
result=stmt.executeQuery(sqlstmt);
while(result.next())
{
print(strfmt("Empname:%1",result.getString(1)));
}
pause;
CodeAccessPermission::revertAssert();

}

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    239,932 Most Valuable Professional on at

    Use setDSN() and sertDatabase() method of LoginProperty to define where you want to connect. Of course, you have to set up an ODBC DSN before you can use it from AX. There is an example in documentation: How to: Connect to an External Database from X++ Code.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Ax32.exe is a 32-bit application for which you probably need to use the ODBC 32-bit System / User DSN, if you execute your code in a Job.

    What I would recommend is to set up the ODBC datasource as 64-bit on your AX AOS instance, and write a class that executes on Server-tier (by using "server static" keywords on the class method, or setting the RunOn property to Server from Called from on the Class properties), generate CIL and run the whole code on server side.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Sanhthosh.Kumar.K Profile Picture

Sanhthosh.Kumar.K 2

#2
Raed Salah Bzour Profile Picture

Raed Salah Bzour 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans