MATLAB: Do I get an error message when using the FETCH command within a loop in the Datafeed Toolbox 3.0 (R2007b)

Datafeed Toolbox

I am using the Datafeed Toolbox to get data for multiple securities from the Bloomberg data server. The list of securities is stored as a cell array of strings and I'm using the following command, within a loop, to retrieve the data
data = fetch(bloomberg, ticker{i}, 'TIMESERIES', {'10/01/2008 9:30:00', '10/5/2008 9:35:00'},5);
After about 120 iterations I get the following error message
??? Error using ==> bloomberg at 39
Cannot find Bloomberg license or API software

Best Answer

This error is thrown because of multiple handles to a Bloomberg connection created by the BLOOMBERG command provided as the first argument in the call to the FETCH command. If these handles are not closed while instantiating more and more the above error message is thrown.
This issue can be avoided by instantiating the connection once before the FETCH command and using that instance to retrieve data. The code would be of the following form:
b = bloomberg;
for i=1:10
data = fetch(b, ticker{i}, 'TIMESERIES', {'10/01/2008 9:30:00', '10/5/2008 9:35:00'},5);
end
close(b);