4.07143

4.1 | 29 ratings Rate this file 80 Downloads (last 30 days) File Size: 13.16 KB File ID: #8385

database connection mfiles

by Tim Myers

 

29 Aug 2005 (Updated 23 Mar 2007)

Queries datasource directly w/o requiring mods to ODBC Data Source Administrator.

| Watch this File

File Information
Description

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!

Acknowledgements
This submission has inspired the following:
ADO OLE Database Connection, adodb_tools
MATLAB release MATLAB 7.3 (R2006b)
Other requirements Since these functions use ActiveX controls, they are probably limited to Windows users.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (37)
10 Sep 2005 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 ?
 

10 Sep 2005 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 ?
 

20 Dec 2005 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);

08 Feb 2006 Tor Hauge  
20 Feb 2006 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.

15 May 2006 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

23 May 2006 Alberto Jucci

Very excellent and useful. Really professional! Thanks Tim!

07 Jun 2006 nasr Hamwe  
28 Jun 2006 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?

04 Jul 2006 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?

26 Jul 2006 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);

18 Sep 2006 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)

05 Oct 2006 asma omairi  
25 Oct 2006 hiba as

it is good

14 Nov 2006 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!

13 Dec 2006 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

25 Jan 2007 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?

16 Mar 2007 pradeep g  
21 Mar 2007 Bo BMB

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

18 Apr 2007 Matteo Borghi

Very helpful!

09 May 2007 Stephane ARMAND  
12 Jun 2007 Darik Gamble

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

01 Nov 2007 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.

13 Mar 2008 Andy Mills  
14 Mar 2008 sh h

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

thanks

06 May 2008 egons kaktuss

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

10 Jun 2008 George Zhao

very helpful to connect to ACCESS server.

Will it work for mySQL?

23 Sep 2008 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

14 Oct 2008 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.

18 Dec 2008 koubaa kamal

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

09 May 2009 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 ...

15 Jun 2009 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);

04 May 2010 Daniel

Fantastic.

12 Oct 2010 Robin den Dekker

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

04 Jan 2011 Azarudeen A

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

20 Sep 2011 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?

25 Nov 2011 Walid Al-Gherwi  
Please login to add a comment or rating.
Updates
23 Mar 2007

Updated oledbquery.m to enable inerting and updating records. Added examples to README.txt. Added help text in catch section of oledbcn.m when database connection cannot be made.

Tag Activity for this File
Tag Applied By Date/Time
data import Tim Myers 22 Oct 2008 07:59:04
data export Tim Myers 22 Oct 2008 07:59:04
database Tim Myers 22 Oct 2008 07:59:04
query Tim Myers 22 Oct 2008 07:59:04
oracle Tim Myers 22 Oct 2008 07:59:04
sql Tim Myers 22 Oct 2008 07:59:04
recordset Tim Myers 22 Oct 2008 07:59:04
access Tim Myers 22 Oct 2008 07:59:04
myers Tim Myers 22 Oct 2008 07:59:04
datasource Tim Myers 22 Oct 2008 07:59:04
access Timon 16 Nov 2009 07:09:38
access Lucia 04 Dec 2009 07:49:55
database Paul 17 Sep 2010 16:29:36
access Francisco Mejías Ruiz 16 Dec 2010 06:33:54
access Jan 29 Apr 2011 08:17:57
database Nayla El-Haber 31 Jan 2012 14:06:45
access Nayla El-Haber 31 Jan 2012 14:06:46

Contact us at files@mathworks.com