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)

Can we have multiple ResultSet objects opened simultaneously for identical SELECT statements execution in x++

(0) ShareShare
ReportReport
Posted on by

Error : SQL error description: [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt

Need help!

Hi Team,

when I am trying to execute 3 select statements in one ODBC connection i getting above error because of the multiple resultSet objects. The values from select statements resultSet will be used in another select statement where condition? So what is the best approach to address this issue as I need to execute them in an external database?  

//Pull data from sql server.
void getDataFromSql()
{

lConStr = this.getConnStr();

if (!lConStr)
{
throw error("Database connection setup not found !!");
}
try
{
lloginProperty = new LoginProperty();
lloginProperty.setOther(lConStr);
lOdbcCon = new ODBCConnection(lloginProperty);

if(lOdbcCon)
{

lExportSQLQry = "SELECT * from ....";

//Assert permission for executing the sql string.
lSqlPermission = new SqlStatementExecutePermission(lExportSQLQry );
lSqlPermission.assert();

//Prepare the sql statement.
lstatement = lOdbcCon.createStatement();
gExportResultSet = lstatement.executeQuery(lExportSQLQry);
CodeAccessPermission::revertAssert();
lstatement.close();

//Cause the sql statement to run,
//then loop through each row in the result.
while (gExportResultSet.next())
{
lMasterSQLQry = "";

lMasterSQLQry += "SELECT * from....


//Assert permission for executing the sql string.
lSqlPermission = new SqlStatementExecutePermission(lMasterSQLQry);
lSqlPermission.assert();

//Prepare the sql statement.
lstatement = lOdbcCon.createStatement();
gMasterResultSet = lstatement.executeQuery(lShipMasterSQLQry);
CodeAccessPermission::revertAssert();
lstatement.close();

while(gMasterResultSet.next())
{
lDetailsSQLQry = "";

lDetailsSQLQry += "SELECT * from.....

//Assert permission for executing the sql string.
lSqlPermission = new SqlStatementExecutePermission(lDetailsSQLQry);
lSqlPermission.assert();

//Prepare the sql statement.
lstatement = lOdbcCon.createStatement();
gDetailsResultSet = lstatement.executeQuery(lDetailsSQLQry);
CodeAccessPermission::revertAssert();
lstatement.close();

while(DetailsResultSet.next())
{
XXXXXXXX
}
}

lSqlPermission = new SqlStatementExecutePermission(gCtrlMgrSQLQry);
lSqlPermission.assert();

lstatement = lOdbcCon.createStatement();
lstatement.executeUpdate(gCtrlMgrSQLQry);
CodeAccessPermission::revertAssert();
lstatement.close();
}

}
}
catch
{
if (lSqlPermission)
CodeAccessPermission::revertAssert();

if (lstatement)
lstatement.close();

throw error("Failed to transfer data to SQL server !!");
}

}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Can we have multiple ResultSet objects opened simultaneously for identical SELECT statements execution in x++

    When you paste code select Use rich formatting, and the Code pattern button </> since your current pasting is unreadable!

    Did you try using separate ODBC connection objects for each statement, since it is blocked in single connection?

  • Community Member Profile Picture
    on at
    RE: Can we have multiple ResultSet objects opened simultaneously for identical SELECT statements execution in x++

    Hi Vilmos,

    Thanks for the response.

    I will try using separate ODBC connect to execute each result set.  

  • Community Member Profile Picture
    on at
    RE: Can we have multiple ResultSet objects opened simultaneously for identical SELECT statements execution in x++

    Hi Vilmos,

    I tried with separate ODBC connection and its working perfectly. But for 4 result sets i have open 4 odbc connections .

  • Vilmos Kintera Profile Picture
    46,149 on at
    RE: Can we have multiple ResultSet objects opened simultaneously for identical SELECT statements execution in x++

    That does not sound like a problem as long as your DB server is covered by enough concurrent CALs.

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
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Community Member Profile Picture

Community Member 2

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans