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!
Tim Myers (2021). database connection mfiles (https://www.mathworks.com/matlabcentral/fileexchange/8385-database-connection-mfiles), MATLAB Central File Exchange. Retrieved .
Inspired: ADO OLE Database Connection, adodb_tools
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
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/
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
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?
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?
where should i place these files exactly in matlab
thanks !
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?
This connectivity doesn;t work in matlab 2010. It says the available activeX control doesnt have the required control.
Anyone made this work with a connection between Matlab and MS-SQL?
Would appreciate it!
Fantastic.
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);
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 ...
this a very good work, made my file simple ;)
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.
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
very helpful to connect to ACCESS server.
Will it work for mySQL?
One of the rare moments, when it is extrimly usefull, what you get from internet searching :)
How could I connect to an Oracle 10gXE database in detail? what could i specify in my string exactly.
thanks
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.
Out of curiosity, has anyone tried any speed comparisons with this package against Matlab's database toolbox?
Very helpful!
Works fine. If using on computer wo office, install office web components first. (download owc10.exe from Microsoft)
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?
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
Great! This is literally *exactly* what I was looking for. It is a great tool which links two different worlds of programming. Thanks!
it is good
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)
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);
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?
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?
Very excellent and useful. Really professional! Thanks Tim!
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
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.
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);
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 ?
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 ?