Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MATLAB SQL SERVER DATABASE CONNECTION

Posted on 2015-02-20
13
Medium Priority
?
715 Views
Last Modified: 2016-03-02
Hi,

I am using MATLAB R2011a (64bit) and try to connect to SQL SERVER but keep getting connection error. Should I use ODBC or JDBC. How to use them to connect?

Thanks.

Jennifer
0
Comment
Question by:jfz2004
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 3
13 Comments
 
LVL 14

Expert Comment

by:Nakul Vachhrajani
ID: 40621971
I would use ODBC to connect to SQL Server. What's the error that you are facing?
0
 

Author Comment

by:jfz2004
ID: 40621978
Thanks,
My ODBC is 64bit too. But I get this:

ans =

[Microsoft][ODBC Driver Manager] Invalid string or buffer length Please verify that login information and database url are valid.

My co-worker uses 32 bit for both MATLAB and ODBC driver and it works.

But I have to use 64 bit.
0
 
LVL 14

Expert Comment

by:Nakul Vachhrajani
ID: 40621991
Looks like there is a general issue with Mathworks and 64-bit versions of the ODBC driver: http://www.mathworks.com/matlabcentral/newsreader/view_thread/308517

and

http://www.mathworks.com/matlabcentral/answers/93553-why-do-i-get-the-error-invalid-string-or-buffer-length-when-using-an-odbc-driver-with-the-database (This 2nd link also contains a URL to the MatLab documentation for database connectivity).
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

Author Comment

by:jfz2004
ID: 40622052
Thanks. But the 2nd link does not allow me to access the answer. It requires a license number. I entered the license number, it says that license already has a user. So I am following JDBC. But it is so complex that it needs me to create a file called javalibrarypath.txt in a folder that does not even exist on my C:\ drive.

I am so frustrated.
0
 

Author Comment

by:jfz2004
ID: 40622056
According to MatLab's instruction, I need to 2 run the prefdir command in the MATLAB Command Window. The output of this command is a file path to a folder on your computer. But that folder is not on my computer C:\ drive.
0
 
LVL 14

Expert Comment

by:Nakul Vachhrajani
ID: 40622068
Are you referring to the C:\DB_Drivers folder shown as an example on the page: http://in.mathworks.com/help/database/ug/microsoft-sql-server-jdbc-windows.html?
I believe that folder is created as a part of the driver deployment and that it can be changed by the user.
0
 
LVL 15

Accepted Solution

by:
yuk99 earned 2000 total points
ID: 40622078
Once you download and install/unpack jdbc driver (http://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx), you should have a jar file (try one in x64 directory).

Then in your code:

% add path to the JAR file you just installed to Java dynamic classpath
javaaddpath('full_path_to_folder\filename.jar')

Open in new window


Then you can connect to a database following example here:
http://www.mathworks.com/help/database/ug/microsoft-sql-server-jdbc-windows.html#bt8kmbi-3

If something doesn't work, try to follow this page:
http://www.mathworks.com/help/database/ug/microsoft-sql-server-jdbc-windows.html
0
 

Author Comment

by:jfz2004
ID: 40622082
Thank you. Will try it.
0
 

Author Comment

by:jfz2004
ID: 40625628
Hi,

Thanks for the help, yuk99. I tried the instructions on the link: http://www.mathworks.com/help/database/ug/microsoft-sql-server-jdbc-windows.html#bt8kmbi-3

But at step 5, Set up the data source using Database Explorer.
I cannot find Database Explorer on my MATLAB R2011a.
Where is the Database Explorer. I really don't like the different incompatible versions!

Please somebody, how to find the Database Explorer on R2011a. Thank you!
Jennifer
0
 
LVL 15

Assisted Solution

by:yuk99
yuk99 earned 2000 total points
ID: 40626870
Database Explorer is not available in 2011a version.
Look in the archived documentation for how to work with databases.

Check these links (you might need a Mathworks account to access it):
Working with Databases
http://www.mathworks.com/help/releases/R2011a/toolbox/database/ug/bq89k8o-1.html
Configuring Your Environment
http://www.mathworks.com/help/releases/R2011a/toolbox/database/gs/braiey2-1.html

Anyway, why do you need Database Explorer? Have you tried to connect to your database with command line (last part of the tutorial)? Do you have any problem with it?
0
 

Author Comment

by:jfz2004
ID: 40628083
Thanks. But I cannot access to the links. I have a license but the end user is not me. I have to change end users which will take at least two days.
0
 
LVL 15

Assisted Solution

by:yuk99
yuk99 earned 2000 total points
ID: 40628168
If you have version 2011a and Database Toolbox, you should have the documentation installed locally. Search for database function. Please confirm here that you do have the toolbox installed. Run ver command to check it.

I can try to help you to connect to a database. What is your current status? Have you found and install the driver for SQL server? Did you run javaaddpath successfully? Have you tried to connect to a database with database function? Do you have all the information about your database: host name, database name, user and password?

Also verify that you can connect to the database onside of MATLAB (with MS Access, for example, although it uses ODBC).
0
 

Author Comment

by:jfz2004
ID: 40628239
I got it after numerous tries.
Now I an including this "integratedSecurity=true" in the URL and it worked!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question