MATLAB: Am I getting the error “Undefined function or method ‘fetch’ for input arguments of type ‘struct’.” when using the FETCH function in Database Toolbox R2010b

Database Toolbox

I am running the following code:
conn=database('myDatabase','','');
curs=exec(conn,'myquery');
curs=fetch(curs);
and am getting the following error:
Undefined function or method 'fetch' for input arguments of type 'struct'.

Best Answer

This commonly happens because the result returned by the DATABASE function was not a valid database object. Check the message field returned by the database function to see why the connection failed:
conn=database('myDatabase','','');
conn.message