File Exchange

image thumbnail

database connection mfiles

version 1.0.0.0 (13.2 KB) by Tim Myers
Queries datasource directly w/o requiring mods to ODBC Data Source Administrator.

5 Downloads

Updated 23 Mar 2007

View License

Complete package for connecting to, querying, and closing connections to SQL, Oracle, and MS Access databases.

The main advantage of these functions is that they implement a "DSN-less" connection, which means you can run queries against a server without having to first add the datasource to your ODBC Data Source Administrator.

Just input the server name, database name, and optional uid/pwd to open a connection using an ActiveX control.

It takes only 4 lines of code to open a connection, run a query, and close the connection. It's that simple!

Cite As

Tim Myers (2021). database connection mfiles (https://www.mathworks.com/matlabcentral/fileexchange/8385-database-connection-mfiles), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (44)

Robert Barbier

It appears the Microsoft Office Data Source Control ActiveX controls OWC10 and OWC11 can be downloaded here:
https://blogs.technet.microsoft.com/srd/2009/07/13/more-information-about-the-office-web-components-activex-vulnerability/

Alessandro

Hello,

It looks I'm not the only one stuck with this issue. Is It possible to have an answer?

I don"t have "Microsoft Office Data Source Control", so I can't run the OXC10_DataSourceControls.
How can I resolve this? DO I have to download a special library?

Thank you,
cheers

Darin McCoy

Great Submission! I was able to connect to my database - but while trying to execute a SQL command - i got this error

??? Invoke Error, Dispatch Exception:
Source: MSDataShape
Description: Data provider failed while executing a provider command.

Any ideas on how to resolve that?

Eduardo

Verify your system has access to one of the
following ActiveX controls:
COM.OWC10_DataSourceControl_10
COM.OWC11_DataSourceControl_11

I just installed the owc10.exe and still don't work. I have Office 2007, might this be the problem?

Eduardo

Nesreen

where should i place these files exactly in matlab

ilyas

thanks !

Walid Al-Gherwi

Brian

I've enjoyed this package for a while on my XP box but it does not work on Windows7-64. Is there a workaround or some other package or approach that will let me open multitudes of MS ACCESS .mdb files?

Azarudeen A

This connectivity doesn;t work in matlab 2010. It says the available activeX control doesnt have the required control.

Robin den Dekker

Anyone made this work with a connection between Matlab and MS-SQL?
Would appreciate it!

Daniel

Fantastic.

G. Cardi

It does not work with Access 2007.

Look here:

??? Invoke Error, Dispatch Exception:
Source: Microsoft JET Database Engine
Description: Unrecognized database format 'V:\SST\Fieldtest_2009\30_Auswertung\MATLAB\GabrielTEST2\adodb\adotest.accdb'.

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

Error in ==> adodb_demo at 30
cn=adodbcn(s);

Saadettin SÜLÜN

hello.
got the following error:


***** OLEDBCN TROUBLESHOOTING *****
Could not create connection.
Verify your system has access to one of the
following ActiveX controls:
COM.OWC10_DataSourceControl_10
COM.OWC11_DataSourceControl_11

?? Error using ==> oledbcn
Could not create connection. See troubleshooting above.

i have same problem how can i solve this its urgent ...

koubaa kamal

this a very good work, made my file simple ;)

J K.

the code is really good...
just needed to know how to add variables to the sql string...
e.g. sql='select * from TestTable where name=myname';
myname being a variable.

Jasleen K.

hello.
got the following error:

***** OLEDBCN TROUBLESHOOTING *****
Could not create connection.
Verify your system has access to one of the
following ActiveX controls:
COM.OWC10_DataSourceControl_10
COM.OWC11_DataSourceControl_11

?? Error using ==> oledbcn
Could not create connection. See troubleshooting above.

i downloaed wc10.exe and ran it,still the same error..please help...urgent...!!
thanks a lot

George Zhao

very helpful to connect to ACCESS server.

Will it work for mySQL?

egons kaktuss

One of the rare moments, when it is extrimly usefull, what you get from internet searching :)

sh h

How could I connect to an Oracle 10gXE database in detail? what could i specify in my string exactly.

thanks

Andy Mills

Matt C

Works very well for my Oracle 9i application and even has very fast acquisition! Note that the inputs to oledbcnstr.m vary by the database you are trying to access, so you may need to enter a '[]' in some fields as an empty placeholder.

Has anyone tried bundling this code in an executable using the Matlab Compiler? I have read reviews on the Mathworks Database toolbox inherently will not work, but I was wondering if this m-code will.

Darik Gamble

Out of curiosity, has anyone tried any speed comparisons with this package against Matlab's database toolbox?

Stephane ARMAND

Matteo Borghi

Very helpful!

Bo BMB

Works fine. If using on computer wo office, install office web components first. (download owc10.exe from Microsoft)

pradeep g

Robert Ducellari

This is really helpful but I'm looking for a possibility to read also the 'FieldName', not only the content of the cells. Please could you help me?

Inosha Wickrama

this is really helpful but I was hoping you could help me on how to uploadm atlab data to access database. I get the data in matalb and try to save it in access table but I keep on getting a connection time out error. Can you help me with it. Plsese

Clint Morrow

Great! This is literally *exactly* what I was looking for. It is a great tool which links two different worlds of programming. Thanks!

hiba as

it is good

asma omairi

Sibylle Kratzer

I have the same problem as mentioned underneath. Could it be due to me haven R13? What can I use to get data from databases in R13 (read only access)

Johannes Germishuizen

Get the following message/error:

>> demo_oledb
Make sure test.mdb is in the current directory
??? No appropriate method or public field OWC10_DataSourceControl_10 for class COM.

Error in ==> H:\MATLAB\Database\oledbcn.m
On line 22 ==> cn=COM.OWC10_DataSourceControl_10;

Error in ==> H:\MATLAB\Database\demo_oledb.m
On line 26 ==> cn=oledbcn(s);

Ryan van laar

I'm also having this problem:

Source: MSDataShape
Description: Impossible d'initialiser le fournisseur de données.

Error in ==> oledbcn at 31
cn.Connection.CommandTimeout=60; %default

...except in english.

BUT only when i launch my (compiled matlab) program from a shell command within a MS Access database. When I double click the compiled .exe file or run the code from Matlab, the database connection works perfectly.

Very strange - possibly something do with the way windows initiates the code?

Alexandre KOZLOV

Doesn't work on my machine.
<pre>
>> cn=oledbcn(s)
22 cn=COM.OWC10_DataSourceControl_10;
??? Invoke Error, Dispatch Exception:
Source: MSDataShape
Description: Impossible d'initialiser le fournisseur de données.

Error in ==> oledbcn at 31
cn.Connection.CommandTimeout=60; %default
</pre>

1. I have the ActiveX used by application.
2. Connection string is "PROVIDER=MSDASQL;DRIVER={Microsoft ODBC for Oracle};SERVER=ME01DEVT;UID=toto;PWD=toto$;".

Any ideas?

nasr Hamwe

Alberto Jucci

Very excellent and useful. Really professional! Thanks Tim!

Ryan van laar

One of the most useful Matlab functions Ive come across.

Can easily be modified to insert data into a database.

In oledbquery.m replace the read rows section with something like this:

%Insert data into table
x=invoke(r);
x=x';

..then make your SQL query an 'insert into'.

Many thanks

J B

Works fine but i have the same appreciation as marwan khalil:
the returned data is in the type of cell arrays and converting this data to double arrays for processing consumes alot of time.

Tor Hauge

D Petrovich

I get the following error,

EDU>> demo_oledb
Make sure test.mdb is in the current directory
??? No appropriate method or public field OWC10_DataSourceControl_10 for class COM.

Error in ==> C:\matlab_sv13\work\MS Access MFiles\oledbcn.m
On line 22 ==> cn=COM.OWC10_DataSourceControl_10;

Error in ==> C:\matlab_sv13\work\MS Access MFiles\demo_oledb.m
On line 26 ==> cn=oledbcn(s);

marwan khalil

this package is working fine but i have a comment on it:
the returned data is in the type of cell arrays and converting this data to double arrays for processing consumes alot of time.
if there exists a way that can reduce this time consuming ?

marwan khalil

this package is working fine but i have a comment on it:
the returned data is in the type of cell arrays and converting this data to double arrays for processing consumes alot of time.
if there a method to reduce this time consuming ?

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

Inspired: ADO OLE Database Connection, adodb_tools

Community Treasure Hunt

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

Start Hunting!