File Exchange

image thumbnail


version (158 KB) by Jaroslaw Tuszynski
Adodb_tools allow communication with different types of databases through ADO OLEDB component.


Updated 15 Jan 2014

View Version History

View License

Package adodb_toolbox allows communication with different types of databases through Microsoft's ADO (ActiveX Data Objects) OLEDB component. The package was designed to work on Microsoft SQL Server, Oracle, Microsoft Access, MySQL and other databases.

This package can connect to dozen different database types, perform wide range of different query types and convert results to MATLAB Struct data structures as well as regular cell tables. Matlab struct output uses similar format as used by xml_io_tools and csv2struct libraries. Reading and writing BLOB objects is supported.

This package can be studied, modified, customized, rewritten and used in other packages without any limitations. All code is included and documented. Software is distributed under BSD Licence (included).

Cite As

Jaroslaw Tuszynski (2021). adodb_tools (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (30)

Jamie May

Is there a way to run an .SQL script file? Like the executeSQLScript function in the Database Toolkit?

David Fardis

Hey Jaroslaw Tuszynski, like this and formatting SQL data online I used

Andrew Lawrenson

Works a treat.
A useful wrapper around the adodb_query for cases were you frequently access the same database could be....

sqlQuery='SELECT * FROM'
data=sqlQueryXXX_Function(sqlQuery) or [data, structure]=sqlQueryXXX_Function(sqlQuery)

function [Table, Struct]=sqlQueryXXX_Function(sqlQuery)
% MATLAB version R2019a
% PURPOSE: Extract data based on the given SQL query from the specified SQL database
DB = adodb_connect('Provider=sqloledb;Data Source=xxx ;Initial Catalog=xxx ;User Id= xxx ;Password= xxx ;');
[Struct, TableCells] =adodb_query(DB,sqlQuery);
DB.release; %Access: Close DB connection
Table = cell2table(TableCells);
Table.Properties.VariableNames=fieldList; %adds headers to the table


Great tool.

Kavitha Guntaka

My script always errors at this line:
if (ado_recordset.State && ado_recordset.RecordCount>0)
The recordset.RecordCount is not reading any value (empty), although my database shows the existence of data (executed the Sql query at the database).
Could you please provide me any suggestions.

Benjamin Grichting

Nice and well working tool! One issue: JSON fields in MySQL/MariaDB seems not to be possible to read out. Is there some workaround?
Source: Microsoft Cursor Engine
Description: Multiple-step operation generated errors. Check each status value.

Eli Ashkenazy

Jaroslaw Tuszynski

@ Darin McCoy: Sorry but I did not used this code in last 4-5 years, so I do not know.

Darin McCoy

I've gotten this error a couple times... is there any way around this?

Invoke Error, Dispatch Exception:
Source: Microsoft Cursor Engine
Description: Out of memory.

javier cruz

Good tool, works great with Windows 7 64 bits and Matlab R2011a!!


Hello Jaroslaw, could you please point me how to insert dates into SQLExpress.

I have tried the follow but is not working

sql=(['INSERT INTO ' tablename ' (Bid,DateTime) VALUES ('num2str(variable1) ',' char({datestr(now,'yyyy-mm-dd HH:MM:SS')})
adodb_query(DB, sql);


Jaroslaw Tuszynski

Reply to Guillaume: Those functions do not use any toolboxes and rely on ActiveX Microsoft's ADO OLEDB tools which should be preinstalled on all Windows machines. May be you are running on non-windows machine? Or maybe there are some issues with your ADO OLEDB tools: I do not know much about them.


Thank you for your reply. I understand for the 64-bit issue. Maybe I am not using the right string and that is what I am missing I think. There seems to be a lot of different connection strings for mySQL but none seems to work for me. Another point I wanted to ask, do I need the Matlab database toolbox to make this work and also a specific version of Matlab?
Thank you!

Jaroslaw Tuszynski

Reply to Guillaume: I did not play with this code for some years now so all I can suggest is to:
1) verify format of the string using or other website.
2) Make sure all the components are either 64-bit or 32-bit. See my comment from 15 Jan 2014


Hello, I ma new to linking matlab to a SQL database and I am getting what I think is a beginner error :

Error using COM.ADODB_Connection/Open
Invoke Error, Dispatch Exception:
Source: Microsoft OLE DB Provider for ODBC Drivers
Description: [Microsoft][Gestionnaire de pilotes ODBC] Source de
données introuvable et nom de pilote non spécifié

when I enter :
DB =

Could anyone help me configure my connection?

Thank you!


Very nice toolbox. In some cases, I get the following error (on an mySQL database):

Error using Interface.Microsoft_ActiveX_Data_Objects_6.1_Library._Recordset/GetRows
Invoke Error, Dispatch Exception:
Source: Microsoft Cursor Engine
Description: Multiple-step operation generated errors. Check each status value.

Error in adodb_query (line 77)
table = ado_recordset.GetRows'; % retrieve data from recordset

Any ideas how I can debug this?


Very useful tool. As Peter suggested it would be nice to have a insert for a table or structure for multiple records

I went ahead and made one since I needed it.

function adodb_insert(conn,tablename,colnames,data)
colnames_char=strjoin(colnames,', ');

switch w.class
case 'table'
case 'struct'


%% MS SQL: Insert two new records
for r=1:m
adodb_query(conn, ['INSERT INTO ' tablename ' (' colnames_char ') VALUES (''' write_str ''' ); ']);

Jaroslaw Tuszynski

Reply to Bruce:
I had the same problem lately after upgrading to 64-bit computer and installing 64-bit MATLAB. Apparently my MS Office was 32-bit and neither this toolbox nor MATLAB Database Toolbox was able to work with it. I solved the problem by uninstalling 32-bit office and reinstalling 64-bit version.


Has anyone got this to work with an access2010 on a 64 bit system? Recently upgraded from 32 to 64 and can no longer connect to my access DBs.


Problem solved... Keywords are a pain :-)


Mostly great. But just tried a query that works in access itself, but fails with "Error using COM.ADODB_Connection/Execute
Invoke Error, Dispatch Exception: Unspecified error" when executed with adodb_query(sql)

Any thoughts on how to figure out what went wrong?

Dan Golding

Fantastic tool, simple and fast!



I have been using these tools for a while now and they have been working great. Unfortunately, they just gave me a new computer and now adodb_connect gives me an error. It was working fine on a 32bit Windows XP computer with MATLAB2010a. Now on a 64bit Windows 7 machine with MATLAB2010b I get the error:
??? Invoke Error, Dispatch Exception:
Source: Microsoft OLE DB Provider for ODBC Drivers
Description: [Microsoft][ODBC Driver Manager] Data source name not found and no default
driver specified

My connection string DOES specify the correct data source and the driver (which IS installed on the new machine).

Any suggestions?


Jaroslaw Tuszynski

Reply to Pete:
I was using this script to add a lot (~60k) of records to access DB, and use access as temporary memory storage to get some MATLAB codes to run on machined with 2GB or RAM. I did not notice any "extreme" slowness, but that might be relative.

The error you see might be due to MS access not supporting multiple queries.

Pete sherer

This is a great script. However it is extremely slow when trying to multiple records to the accessDB. Is there a way to do insert into for multiple records?
Pref.MultipleQuery = true; is not working!
sql = 'INSERT INTO xport (ACCNT,Name) VALUES ("Pers","02")
INSERT INTO xport (ACCNT,Name) VALUES ("Cars","1008") ';
Got error:
??? Invoke Error, Dispatch Exception:
Source: Microsoft JET Database Engine
Description: Missing semicolon (;) at end of SQL statement.

Error in ==> adodb_query at 54
ado_recordset = ado_connection.Execute(sql);


Thanks for this useful contribution -- I have been using ADO similarly for quite a while now. But I have found it broke in MATLAB R2010b onwards.
Have you tried your toolbox in a later version of MATLAB than R2010a?


Great little script, much faster than the database toolbox supplied by matlab. Better documentation would be nice though.


MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!