Solved

MATLAB SQL SERVER DATABASE CONNECTION

Posted on 2015-02-20
13
658 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

615 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