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)

SQL Server Native Client 11.0][SQL Server]Resource ID : 2. The session limit for the database is 300 and has been reached

(0) ShareShare
ReportReport
Posted on by 815

Hi,

I am getting below error when running AX routine for exporting data as BATCH JOB to Azure database using DSN connection.

ERROR:

Microsoft][SQL Server Native Client 11.0][SQL Server]Resource ID : 2. The session limit for the database is 300 and has been reached. See 'go.microsoft.com/fwlink' for assistance. 

Object OdbcConnection could not created.

 

External SQL server database exist in Azure machine. 

DSN connection is created in AOS server using Native client 11.0.

AX code is using this DSN and carrying out two operations.

First one is to create an ODBC connection, run the truncate table statement once.

Second operation is for the insert statement and it is under while loop.

ODBC connection is being created for each new insert statement.

Below is the code that is under the while loop of AX table

While select * from CustTable

{

 odbcConnection = new OdbcConnection(this.getLoginProperty());

perm = new SqlStatementExecutePermission(sql);
perm.assert();
 //Prepare the sql statement.
 statement = odbcConnection.createStatement();
 statement.executeUpdate(sql);

 statement.close();

}

There are more than 300 records in the AX table.

If I run this routine as batch job then I get the error mentioned above.

Is there a way to resolve this error?

Is there a way to have one ODBC connection and run multiple statements?

Any ideas to resolve this error will be appreciated.

Thanks

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    Hi Nadeem,

    Did you try to open ODBC connection outside of the loop, so you won't have 300 open connection, like:

     odbcConnection = new OdbcConnection(this.getLoginProperty());

    while select * from CustTable

    {

        perm = new SqlStatementExecutePermission(sql);
        perm.assert();
        //Prepare the sql statement.
        statement = odbcConnection.createStatement();
        statement.executeUpdate(sql);

        statement.close();

    }

  • Nadeem Profile Picture
    815 on at

    Hi ievgen,

    I was getting error on Perm.assert when I tried to re-use the connection.

    I will try again and confirm .

    Thanks,

  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    Do not forget to revert permissions using CodeAccessPermission::revertAssert();

  • Verified answer
    Nadeem Profile Picture
    815 on at

    I was missing CodeAccessPermission::revertAssert();

    One ODBC connection outside the loop.

    Added below code line after closing the statement and multiple statements started working fine.

    CodeAccessPermission::revertAssert();

    Batch job is working fine as well.

    Thanks ievgen.

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