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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Timeout for ODBCconnection statement

(0) ShareShare
ReportReport
Posted on by

Hi,

I created an ODBCconnection to connect to another SQL server database and then some Statements to execute some operations (select, delete, update etc).
Is there any way to set a timeout time that raise an exception for the statement?

I got a problem because another query on that database block the one I've created and the batch can't proceed.

Thanks

Riccardo

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    If your calling the ODBC connection via the class odbcConnection you can set the timeout and handle the exception as normal.

    If the query is blocked you can do a retry after catching the error.

    More important is why is the query blocking your operation? The query that is blocking is it in the same operation your executing? Try to reschedule the batch job to another time frame?

    Unfortunately i do not have a better answer for you at the moment. Goodluck!

  • Community Member Profile Picture
    on at

    Hi Jack,

    thanks for your answer, but I need more details: how can I set the timeout via code?

    Thx

  • Suggested answer
    Pravasti AK Profile Picture
    2,985 on at

    Hi,

    static public void Main(Args _args)

    {

       LoginProperty loginProperty;

       OdbcConnection odbcConnection;

       Statement statement;

       ResultSet resultSet;

       str sql, criteria;

       SqlStatementExecutePermission perm;

       ;

       // Set the information on the ODBC.

       loginProperty = new LoginProperty();

       loginProperty.setDSN("dsnName");

       loginProperty.setDatabase("databaseName");

       //Create a connection to external database.

       odbcConnection = new OdbcConnection(loginProperty);

       if (odbcConnection)

       {

           sql = "SELECT * FROM MYTABLE WHERE FIELD = "

               + criteria

               + " ORDER BY FIELD1, FIELD2 ASC ;";

           //Assert permission for executing the sql string.

           perm = new SqlStatementExecutePermission(sql);

           perm.assert();

           //Prepare the sql statement.

           statement = odbcConnection.createStatement();

           resultSet = statement.executeQuery(sql);

           //Cause the sql statement to run,

           //then loop through each row in the result.

           while (resultSet.next())

           {

               //It is not possible to get field 3 and then 1.

               //Always get fields in numerical order, such as 1 then 2 the 3 etc.

               print resultSet.getString(1);

               print resultSet.getString(3);

           }

           //Close the connection.

           resultSet.close();

           statement.close();

       }

       else

       {

           error("Failed to log on to the database through ODBC.");

       }

    }

  • Community Member Profile Picture
    on at

    Riccardo,

    You can learn more about the class in the link below.

    msdn.microsoft.com/.../odbcconnection.aspx

    Quick search on google will give you some code results how to use this.

  • Suggested answer
    Community Member Profile Picture
    on at

    Kavitha,

    This will not solve his issue since he will encounter locks as he says. He will need to catch the exception and retry the transaction. If this does not work he will need to build a timeout or reschedule his batch jobs to another timeframe.

    If he is creating the lock himself he needs to check his code. I suggest you do your queries sequentially and not parallel.

  • Community Member Profile Picture
    on at

    Hi Kavitha,

    thx for the reply , we've already did that way, maybe I've not been clear, my question is if there is a way to set a maximum time of response for the query .

    Thx

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans