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

  • Verified answer
    Nadeem Profile Picture
    Nadeem 815 on at
    RE: SQL Server Native Client 11.0][SQL Server]Resource ID : 2. The session limit for the database is 300 and has been reached

    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.

  • Verified answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: SQL Server Native Client 11.0][SQL Server]Resource ID : 2. The session limit for the database is 300 and has been reached

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

  • Nadeem Profile Picture
    Nadeem 815 on at
    RE: SQL Server Native Client 11.0][SQL Server]Resource ID : 2. The session limit for the database is 300 and has been reached

    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
    Mea_ 60,278 on at
    RE: SQL Server Native Client 11.0][SQL Server]Resource ID : 2. The session limit for the database is 300 and has been reached

    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();

    }

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,401 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans