Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Getting error while establishing ODBC connection in AX2012

(0) ShareShare
ReportReport
Posted on by 752

Hi, 

Need urgent help.

I am using below code for establishing ODBC connection but getting error as

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

Please help.

static void SITestODBC(Args _args)
{
    OdbcConnection           oDBCConnection;
    LoginProperty            loginProperty;
    str                      connectionString;


    try
    {
        connectionString = "DSN=RFIDDB_UAT;Database=myTest_db;UID=sa;PWD=$1234;";

        loginProperty = new LoginProperty();
        loginProperty.setOther(connectionString);
        oDBCConnection = new ODBCConnection(loginProperty);
        if(oDBCConnection)
        {
            info("success");
        }
    }
    catch
    {
        throw error("@CHI814");
    }

}

  • Suggested answer
    A.Prasanna Profile Picture
    A.Prasanna 8,175 on at
    RE: Getting error while establishing ODBC connection in AX2012

    also maks sure you are allow required Ports through firewall(s)

    1433 (ODBC)

    netbios (UDP ports 137, 138 & TCP 139 for NetBIOS over TCP)

    Regards,

    Amith Prasanna

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,421 on at
    RE: Getting error while establishing ODBC connection in AX2012

    Hi Rhiushikesh,

    Please check if any permissions have been changed on the external database as well. That could also cause this issue.

  • Rhushikesh R Profile Picture
    Rhushikesh R 752 on at
    RE: Getting error while establishing ODBC connection in AX2012

    Hi Will, I will test the connection directly from Administrative tools first and will update you. It might be the case that the credentials have been changed as before this error I was able establish connection with same code.

  • Verified answer
    WillWU Profile Picture
    WillWU 22,352 on at
    RE: Getting error while establishing ODBC connection in AX2012

    Hi Rhushikesh Raut,

    How did you create your DSN?

    You don't need to put the username and password in your connection string.

    pastedimage1605076560162v1.png

    Try the following code:

    loginProperty = new LoginProperty();
    loginProperty.setDSN("dsnName");
    loginProperty.setDatabase("databaseName");
    odbcConnection = new OdbcConnection(loginProperty);

    Refer to:docs.microsoft.com/.../how-to-connect-to-an-external-database-from-x-code

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,684 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,414 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans