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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

ODBC Connection error

(0) ShareShare
ReportReport
Posted on by

I am sending data from AX 2012 R3 CU10 to ODBC. I get a critical error when calling ODBC however, SQL is still updated. Not sure what could be causing the issue. Please find the code below and error message.

server public static void runOdbcQuery(str _OdbcQuery)
{

LoginProperty loginProperty;
OdbcConnection odbcConnection;
Statement statement;
ResultSet resultSet;
SqlStatementExecutePermission perm;
str connection;
BSKParameters odbc;


// Set the information on the ODBC.
select * from odbc;
loginProperty = new LoginProperty();
connection = "Driver=" + odbc.Driver +";Description="+ odbc.Description +";Server=" + odbc.Server + ";Database="+ odbc.Database + ";UID=" + odbc.UserId + ";PWD=" + odbc.Password + ";";
//connection = "Driver=ODBC Driver 11 for SQL Server;Description=OMS_32;Server=" + odbc.Server + ";Database="+ odbc.Database + ";UID=" + odbc.UserId + ";PWD=" + odbc.Password + ";";

loginProperty.setOther(connection);

// Create a connection to external database.
try
{
odbcConnection = new OdbcConnection(loginProperty);
}
catch
{
throw error("Error creating the ODBC Connection");
}

if (odbcConnection)
{
//Prepare the SQL statement.
statement = odbcConnection.createStatement();
perm = new SqlStatementExecutePermission(_OdbcQuery);
perm.assert();

resultSet = statement.executeQuery(_OdbcQuery);
//resultSet = statement.executeUpdate(sql);

}
resultSet.next();
resultSet.close();
statement.close();

}

Error message relates to Invalid Cursor state and from my research it seems as if the Cursor starts before it should. Not sure how to resolve it though. Appreciate any help.

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: ODBC Connection error

    Which line of code is throwing the error?

  • Suggested answer
    Iulian Cordobin Profile Picture
    8,201 on at
    RE: ODBC Connection error

    I think your T-SQL statement is wrong; can you review that and make sure it is a valid update table t-sql. On second thought, reading closely your code I can see you are doing executeQuery with your update T-Sql, and then a .next()? Or the last code you have here is not erroring out?

  • Community Member Profile Picture
    on at
    RE: ODBC Connection error

    It starts erroring at resultSet.next()

    The ODBC statement runs and when I check SQL the entry exists there, however I believe it's related to a Cursor error. From my reading, it seems as if when I run resultSet.next() it sends through an empty command and that's whats causing it. However I have no idea how to clear the Cursor state

  • Community Member Profile Picture
    on at
    RE: ODBC Connection error

    The T-SQL is correct, as I've run it in SQL Server Management Studio and runs fine.

    The .next() is where the error is occuring, which is weird becasue the insert statement into SQL is successful and the entry exists in SQL

  • Verified answer
    Community Member Profile Picture
    on at
    RE: ODBC Connection error

    The issue is I was sending an Insert SQL command and not a Select, so therefore the Resultset was pointless as I wasn't retrieving any fields back.

    To fix I changed the following line:

    resultSet = statement.executeQuery(_OdbcQuery);

    with the following line:

    statement.executeUpdate(_OdbcQuery);

    And that resolved the issue!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans