I need to connect to the database both from the main program and from functions. After fetching lots of data (200k records) from the database in the main program, the function is not able to connect and get data anymore. I tried to close the connection or the cursor but it's still not working.
This is the code with comments describing where the connection doesn't work anymore:
function FTestConn( ) conn1 = database('DBname', 'Name', 'psw'); isconnection(conn1) end
And the main program:
conn1 = database('DBname', 'Name', 'psw'); isconnection(conn1) %this connection works FTestConn() %this connection works
%fetching some data from the database curs1 = exec(conn1, 'select min(id) from table1'); curs1 = fetch(curs1); T = curs1.data;
%The connection in the function still works FTestConn()
%Fetching A LOT of data from the table curs1 = exec(conn1, 'select distinct id from table1'); %about 200000 records curs1 = fetch(curs1); ID = curs1.data; isconnection(conn1) %the connection still works
%The function cannot connect to the database anymore FTestConn() %result = 0, no connection.