View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
ADO OLE Database Connection

4.7 | 15 ratings Rate this file 17 Downloads (last 30 days) File Size: 13.1 KB File ID: #13621 Version: 1.0

ADO OLE Database Connection


Martin Furlan (view profile)


10 Jan 2007 (Updated )

Queries datasource and insers data into datasource.

| Watch this File

File Information

This code basis on Tim Myers code (oledb*.m) and uses ADO OLE DB instead of OWC - Office Web Component. When OWC not installed (e.g. MS Office 2000) using ADO OLE DB can be a solution. The syntax is similar to Tim Myers code.

The Code is tested only with MS Access database.


Database Connection Mfiles inspired this file.

This file inspired Adodb Tools.

MATLAB release MATLAB 7.3 (R2006b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (20)
18 May 2016 Olivier

Solution provided by super heasy worked for me (Win7x64, MATLAB R2016a). Great work!
Do not forget to edit adodbcnstr.m

17 Apr 2016 super heasy

for this problem "Error using COM.ADODB_Connection/Open",
because using Winx64,and "Microsoft.Jet.OLEDB.4.0"is not support .
So download and install "AccessDatabaseEngine_X64.exe",then replace "Microsoft.Jet.OLEDB.4.0" with "Microsoft.ACE.OLEDB.12.0" in <adodbcnstr.m>.
It works in Win10x64 and MATLAB 2016a.

27 Mar 2012 sweta cccc

thanks alot for the code...
jus need a little help...
i need to add a variable value into the database. eg: var1=1234; i need to store this variable value into the database.

Comment only
05 Mar 2012 mingke

mingke (view profile)

there is an error in open connection. Has anybody had this problem ?

Error using COM.ADODB_Connection/Open
Invoke Error, Dispatch Exception:
Source: Microsoft OLE DB Provider for SQL Server
Description: Cannot open database "E:\database\MyFinancialDatabase.mdf" requested by the login. The login

Error in adodbcn (line 29)
invoke(cn,'Open', cnstr);

Error in demoFromIlovematlab (line 13)

24 Feb 2012 David malins

I'm having an error invoking the ADODB.connection. Has anybody had this problem and managed to resolve it?

??? Invoke Error, Dispatch Exception:
Source: ADODB.Connection
Description: Provider cannot be found. It may not be properly installed.
Help Context ID: 12ee4f

Error in ==> adodbcn at 29
invoke(cn,'Open', cnstr);

Error in ==> PI_WL at 9
cn = adodbcn(cnstr)

I'm using win xp and 32-bit matlab R2010a.

Comment only
12 Jan 2012 Robert Daly

This is a great tool, I have been using it for a while with out a hitch. Just recently it started to go wrong and gave the error:
"No public field CursorLocation exists for class COM.ADODB_Connection"
I found if I commented out the folowing line from adodb_connect
ado_connection.CursorLocation = 'adUseClient'; % Uses a client-side cursor supplied by a local cursor library
this error went away.
After this it had a problem with the line from adodb_query...
if (ado_recordset.State && ado_recordset.RecordCount>0)

I found if I delete this (and the corresponding end) it works fine for my purposes. I'm not exactly sure what this did (anybody?) and what errors will crop up now that it isn't there.
I wonder if there has been an update to the ADODB set up and now some of the methods and classes have changed since this code was written.

Comment only
20 Sep 2011 Brian

Brian (view profile)

I'm getting this error on Win7 64 box:

Make sure adotest.mdb is in the current directory
??? Invoke Error, Dispatch Exception:
Source: ADODB.Connection
Description: Provider cannot be found. It may not be properly installed.
Help File: C:\Windows\HELP\ADO270.CHM
Help Context ID: 12ee4f

Error in ==> adodbcn at 29
invoke(cn,'Open', cnstr);

Error in ==> adodb_demo at 30

Comment only
13 Jan 2011 Kevin

Kevin (view profile)

does somebody have an example of running this with Oracle i keep getting an error.
??? Invoke Error, Dispatch Exception:
Source: Microsoft OLE DB Provider for ODBC Drivers
Description: [Oracle][ODBC][Ora]ORA-12154: TNS:could
not resolve the connect identifier specified

Comment only
23 Nov 2010 Fredrik

Fredrik (view profile)

09 May 2010 Vinod Karanth

Very effective. Thanks heaps.

24 Feb 2009 Guyennon Nicolas

Thanks a lot !!! Amazing work, even faster than Tim Myers code (oledb*.m)
I'm working with your toolbox to query access 2003 database.
I was looking for table, field and query information. Tooks me 4 days ... hope that could help someone else

%% get table name
sqltablename='SELECT name FROM MSysObjects WHERE Type=1 AND Flags=0 ORDER BY name';
%% get query name
sqlqueryname='SELECT name FROM MSysObjects WHERE Type=5 AND Flags=0 ORDER BY name';

note that in both case you should first change users authorization to read for MSysObjects opening your access database. ("user and group authorization" menu in tools)

the hardest part was to get fields or columns name ...

function field_name=tablefieldname(cn,table_name)
%% find all field name from table
sqlfiledname=['SELECT * FROM ' table_name];
r = invoke(cn,'Execute',sqlfiledname);
for ff=1:nbfileds


14 Oct 2008 Leen K.

want to use variables in the sql queries...
kindly suggest a way.
e.g. sql=['select * from TestTable where firstname=',myname ,'];
5this statement wont replace variable myname

23 Sep 2008 Jasleen K.

Thanks a tonne..!!!!
solved my problem.!!

28 Aug 2008 deepa deepa

25 Jul 2008 Laszlo Sragner


Maybe the leak was due to the 'release' command at the end instead of 'delete'

22 Mar 2008 hardik nadiyana

really help ful thanx,

27 Feb 2008 jairo Ortiz

04 Jan 2008 Christy Lynch

This is a fantastically easy interface to use for Access databases. The problem is a memory leak. Releasing the connection and clearing the connection variable does not release the memory used up by the connection. Only restarting Matlab seems to work.

26 Oct 2007 Martijn Koopman

Very easy to use and extremely fast interface with Microsoft Access *.MDB files.

26 Apr 2007 Ryan Schaezler

Works well. I was having problems with OWC even though it was install on one computer. Using the ADODB connection worked without any issues.

Contact us