Thursday, April 15, 2010

Connect to SQL Server from Matlab

To connect to SQL Server from Matlab can be a very tricky task, specially because the ODBC connectivity is implemented in Matlab by using a JDBC bridge to ODBC technology, I spent almost 3 hours trying to use ODBC connectivity, after that I moved to the JDBC driver, the installation process is a little bit tricky, the process is the following:

1. Download the JDBC driver from Microsoft from:

2. Execute it, in will be decompressed to the selected location

3. Start the Notepad application as administrator and open the file:

C:\Program Files\MATLAB\R2010a\toolbox\local\classpath.txt

4. Add a reference like this to the JDBC driver after the last line of that file:


5. After that you have to restart MATLAB and then you can test the connection:

dbConn = database('master', 'user', 'password', '', 'jdbc:sqlserver://localhost:1433;databaseName=master;');

6. To test the connection you can execute:


7. Please not that the local instance of SQL Server require to have the TCP/IP protocol network connections enabled.

No comments:

Post a Comment