AX X++ return reader form method and close connection to database

341 views Asked by At

Dynamics AX : I am fetching data from an external server using OLEDB Connection in X++ class in order to insert it into the application/AX database .

However, I have created a class that contains a method getreader this method will create a connection to an external database and then return an System.data.oled.oledbdatareader as output and this output will be processed by another class to do the necessary computation.

Furthermore, the above method will be called by many classes not only one which make me worried about the number of connection opened with the database especially I didn't manage to close it after returning the reader.

I googled how to close connection while returning the reader and I have concluded that I can close the connection as per the below

connection.ExecuteReader(CommandBehavior.CloseConnection)

The above code is written in c# and I couldn't do the same in X++.

How could I solve the problem in dynamics AX and what is the impact of keeping the connection open?

1

There are 1 answers

0
Matej On

You can wite as connection.ExecuteReader(System.Data.CommandBehavior::CloseConnection);

I'm not sure if this works as reader could not move to the next row if the connection would be closed.