How can I access a SQL Server database with a JDBC driver if I have Windows Authentication using Database Toolbox 3.5 (R2008b)?

16 views (last 30 days)
I am a Windows Authenticated User of the SQL Server Database. I want to know if I can access the database with JDBC drivers using the Database Toolbox.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Jan 2024
Edited: MathWorks Support Team on 29 Feb 2024 at 12:22
This change has been incorporated into the documentation in Release R2011a.
For the latest release, please refer to:
 
For troubleshooting, see below, as well as the following documentation on Database Connection Error Messages:
Please run the below command in the MATLAB R2018b command window to get the release specific documentation
web(fullfile(docroot, 'database/ug/database-connection-error-messages.html'))
For releases prior to R2011a, read below for any additional information:
To connect to a SQL Server database with Integrated Windows Authentication using JDBC driver, you would need to follow the steps below:
1. Close MATLAB if it is running.
2. Insert the path to the JAR file of the database driver to the "classpath.txt" file:
- The file is located at:
$MATLABROOT\toolbox\local\classpath.txt
- The path entry should include the full path to the driver, for example as follows:
C:\DB_Drivers\sqljdbc_2.0\enu\sqljdbc4.jar
Please choose the right driver file as per the version of JRE MATLAB uses.
sqljdbc4.jar should be used for JRE 6.0 or higher. Please refer to the following link from MSDN documentation for choosing the right jar file and avoiding connection errors.
Note: $MATLABROOT is the installation directory of MATLAB, whose value is obtained by typing the following command at the MATLAB command prompt:
matlabroot
Also note that using JAVAADDPATH will not work when Integrated Windows Authentication is required.
3. Insert the path to the folder containing "sqljdbc_auth.dll" to the "librarypath.txt" file:
- The file is located at:
$MATLABROOT\toolbox\local\librarypath.txt
- The path entry should not include the file name sqljdbc_auth.dll, it should be for example as follows:
C:\DB_Drivers\sqljdbc_2.0\enu\auth\x64
The sqljdbc_auth.dll file is installed in the following location:
<installation_directory>\sqljdbc_<version>\<language>\auth\<arch>
... where <installation_directory> is the installation directory of SQL Server Driver.
Note:
- If you are running a 32-bit Java Virtual Machine (JVM), use the sqljdbc_auth.dll file in the x86 folder, even if the operating system is the x64 version.
- If you are running a 64-bit JVM on a x64 processor, use the sqljdbc_auth.dll file in the x64 folder.
- If you are running a 64-bit JVM on a IA-64 processor, use the sqljdbc_auth.dll file in the IA64 folder.
4. Start MATLAB.
5. Append the string "integratedSecurity=true;" to the database URL, for example as follows:
conn = database('dbName','','','com.microsoft.sqlserver.jdbc.SQLServerDriver','jdbc:sqlserver://servername:portnumber;database=dbName;integratedSecurity=true;')
TROUBLESHOOTING:
* The error:
ERROR: JDBC Driver Error: com.microsoft.sqlserver.jdbc.SQLServerDriver. Driver Not Found/Loaded.
... can occur if:
- The full path to the JAR file was not added to the classpath.txt file, also if it was only added using the JAVAADDPATH command.
- The path to the JAR file is wrong; make sure that the path is not misspelled.
* The warning:
ERROR: com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit>
WARNING: Failed to load the sqljdbc_auth.dll
... can occur if:
- The path to the folder containing the file sqljdbc_auth.dll was not added to the librarypath.txt file.
- If the full path to the file was added instead of the path to the folder.
- If the path to the 64-bit version of the DLL was added when using a 32-bit JVM.
- If the path to the 32-bit version of the DLL was added when using a 64-bit JVM.
* The message:
ERROR: Login failed for user 'DOMAIN\username'.
... can occur if:
- The used login credentials are wrong.
- If the user account does not have enough rights to access the remote machine.
- The database server is not configured to accept Integrated Windows Authentication logins.
* The error:
ERROR: The property integratedSecurity does not contain a valid boolean value. Only the values true or false can be used.
... can occur if:
- The semicolon (;) after the value assigned to the integratedSecurity property was omitted.
For Microsoft(R) Windows Vista(TM) users:
* The error:
ERROR: No suitable driver found for
jdbc:sqlserver://servername:portnumber;database=dbName;integratedSecurity=true;
... can occur if:
- You installed MATLAB in the "Program Files" folder and User Account Control (UAC) is enabled.
To work around this issue, either:
a) Start MATLAB by right-clicking on its icon and running it as an administrator (elevated execution).
b) Disable UAC.
c) Install MATLAB in another folder, for example in "C:\MATLAB\...".
Please follow the below link to search for the required information regarding the current release:

More Answers (0)

Categories

Find more on Reporting and Database Access in Help Center and File Exchange

Products


Release

R2008b

Community Treasure Hunt

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

Start Hunting!