MATLAB SQL SERVER DATABASE CONNECTION

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
jfz2004Asked:
Who is Participating?
 
yuk99Connect With a Mentor Commented:
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
 
Nakul VachhrajaniTechnical Architect, Capgemini IndiaCommented:
I would use ODBC to connect to SQL Server. What's the error that you are facing?
0
 
jfz2004Author Commented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Nakul VachhrajaniTechnical Architect, Capgemini IndiaCommented:
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
 
jfz2004Author Commented:
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
 
jfz2004Author Commented:
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
 
Nakul VachhrajaniTechnical Architect, Capgemini IndiaCommented:
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
 
jfz2004Author Commented:
Thank you. Will try it.
0
 
jfz2004Author Commented:
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
 
yuk99Connect With a Mentor Commented:
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
 
jfz2004Author Commented:
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
 
yuk99Connect With a Mentor Commented:
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
 
jfz2004Author Commented:
I got it after numerous tries.
Now I an including this "integratedSecurity=true" in the URL and it worked!
0
All Courses

From novice to tech pro — start learning today.