Solved

MATLAB SQL SERVER DATABASE CONNECTION

Posted on 2015-02-20
13
613 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 13

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 13

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 13

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 500 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 500 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 500 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reformat SQL - so SSRS can read the columns 25 47
How can I find this data? 3 41
debug user defined function in visual studio 2015 2 51
SQL Server Serialization error 8 48
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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