Solved

MATLAB SQL SERVER DATABASE CONNECTION

Posted on 2015-02-20
13
490 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
  • 7
  • 3
  • 3
13 Comments
 
LVL 11

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 11

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
 

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 11

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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now