How do I deploy a MATLAB function which uses Database Toolbox functionality with Microsoft SQL Server Integrated Security?

16 views (last 30 days)
I am using a Database connection to a Microsoft SQL Server with Integrated Security in my MATLAB function. I had to update librarypath.txt and classpath.txt and then this works fine inside MATLAB. Now I want to use MATLAB Compiler to create a standalone application. How do I include sqljdbc4.jar and sqljdbc_auth.dll in my application such that it can also use the database connection with integrated security?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 24 Feb 2016
The most portable way to deploy such an application would be the following:
For MATLAB/Database Toolbox releases R2012b and newer:
1. When following the instructions to add the directory containing the authentication DLLs to the MATLAB Java Library Path, do not work with $MATLABROOT\toolbox\local\librarypath.txt but use $PREFDIR\javalibrarypath.txt instead. (Where $PREFDIR stands for the directory returned by the prefdir function. Further javalibrarypath.txt does not exist by default so you may need to create it by yourself). When writing the file, do not only add the directory containing the DLL on your development machine; also add a line containing a single dot. The MCR will interpret this dot as "the current directory", this will allow us to place sqljdbc_auth.dll next to your EXE-file of the deployed application. (Note that $PREFDIR\javalibrarypath.txt automatically gets compiled into the application at compile time).
2. Compile sqljdbc4.jar into your application by adding it to the "Shared Resources and Helper Files" (or "Files required for your application to run" in later MATLAB versions) in DEPLOYTOOL or by using the -a option with MCC.
3. Whenever you distribute your application to someone else, make sure that sqljdbc_auth.dll is indeed placed next to the EXE-file.
For MATLAB/Database Toolbox releases R2012a and earlier:
1. Compile sqljdbc4.jar into your application by adding it to the "Shared Resources and Helper Files" in DEPLOYTOOL or by using the -a option with MCC.
2. Create a copy of your librarypath.txt and in this copy replace the directory name of the directory containing sqljdbc_auth.dll with a single dot "." (without the quotes). MATLAB will interpret this dot as "the current directory".
3. Place this new librarypath.txt in the same directory as your standalone EXE-file (i.e. which at runtime will be "the current directory" as above). Also place sqljdbc_auth.dll in this directory.
4. Whenever you distribute your application to someone else, make sure that librarypath.txt and sqljdbc_auth.dll are indeed placed next to the EXE-file.
  6 Comments

Sign in to comment.

More Answers (4)

Damir
Damir on 13 Feb 2014
Hi
I am using Matlab 2013b on Win7.
I have included path to jdbc driver to $PREFDIR\javalibrarypath.txt. This path is used to load driver in Matlab.
To use the jdbc driver in an executable I compile using -a option as proposed above. The problem is that I get the following warning:
>> mcc -m test_db -a 'c:\JDBC_drivers\ojdbc14.jar'
Warning: "c:\JDBC_drivers\ojdbc14.jar" is already
specified on static java path.
> In javaclasspath>local_validate_dynamic_path at 285
In javaclasspath>local_javapath at 182
In javaclasspath at 119
In javaaddpath at 69
I assume this is because the file is already specified in $PREFDIR\javalibrarypath.txt. Everything works fine, but it is annoying to get the warning.
Is it still supported to include the jdbc driver to $MATLAB\toolbox\local\classpath.txt?
Thanks Damir

florian
florian on 21 May 2015
Edited: florian on 21 May 2015
I had troubles with a jDBC connection to MS SQL server, because I was not aware that the deployed applications have to be started from a local drive...Otherwise the integrated security authentification has not worked ...see also the AdoDB case...

keith Runyon
keith Runyon on 10 Aug 2015
can you import the data with active x and still be able to export as a standalone package in matlab compiler?

keith Runyon
keith Runyon on 10 Aug 2015
can you import the data with active x and still be able to export as a standalone package in matlab compiler?
  1 Comment
florian
florian on 16 Sep 2015
yes my deployed application works with a COM (Ado.Db) connection...thus jDBC dependencies (jar, dll for integrated security) can be avoided

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!