I have a .vbs file on my computer that accesses a database and creates a text file of the info in the database. How do i have MATLAB tell this file to run? I tried the open command and all it did was open the script in a MATLAB editor.
Also, I have attempted accessing the database with the Database Toolbox but that has given me issues. I am attempting running the .vbs file as a work around for the time being.
-Jason

 Respuesta aceptada

Guillaume
Guillaume el 14 de Feb. de 2016
Editada: Guillaume el 14 de Feb. de 2016

3 votos

Possibly:
system(sprintf('cscript.exe "%s"', 'c:\full\path\to\your\script');
Considering that vbs scripts tend to just contain calls to activex (COM) objects which matlab can also do, you may as well rewrite the script in matlab. It's more maintainable in the long run.

5 comentarios

Jason Allnutt
Jason Allnutt el 15 de Feb. de 2016
Thank you so much. Unfortuantely, the script performs a call to a SQL Database and pulls in all the data of that database. I am having trouble running the database toolbox (i.e. sometimes it fails, other times it doesn't pull in all the data, sometimes it works fine).
Thank you for your answer though.
-Jason
Guillaume
Guillaume el 15 de Feb. de 2016
Your script is using some activex object (possibly ADODB) to query to the database, you can make the exact same calls directly from matlab, without the database toolbox, just using the same activex object. For example, if your script includes:
Set Connection = CreateObject("ADODB.Connection")
Connection.Open "DSN=x;UID=u;PWD=p;Database=db"
Set Recordset = CreateObject("ADODB.Recordet")
Recordset.Open query,Connection
That would translate in matlab as:
Connection = actxserver('ADODB.Connection');
Connection.Open('DSN=x;UID=u;PWD=p;Database=db');
Recordset = actxserver('ADODB.Recordset');
Recordset.Open(query, Connection);
This just involves base matlab. To be honest, I've never felt the need for the database toolbox to communicate with databases.
Jason Allnutt
Jason Allnutt el 16 de Feb. de 2016
Editada: Jason Allnutt el 17 de Feb. de 2016
Wow, i'm obviously very new to this. And did not know I could do this. Thank you very much for your response. I will have to attempt this.
-Jason
Jason Allnutt
Jason Allnutt el 18 de Feb. de 2016
Hey Guillaume,
I could use some help using the activex controls to connect to my SQL sever. When i run the second command I get "Error using COM.ADODB_Connection/Open".
I'm 99% sure i have the correct DSN, UID, PWD and Database name. But I have limited knowledge of activex controls, so possibly you could point me in the direction to figure get some more knowledge on this. Anything would be most appreciated.
-Jason
Jason Allnutt
Jason Allnutt el 18 de Feb. de 2016
I figured it out. I needed to set the provider and rename a couple of the fields.
However, I am having trouble finding the equivalent to the "fetch" command in the DB toolbox. I have my Recordset.Open exectuing. But now, to save the data i'm capturing to a variable, I'm unsure.
-Jason

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 14 de Feb. de 2016

Comentada:

el 18 de Feb. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by