How do I connect to an MS SQL database through JDBC in a deployed Web App?
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 4 Feb 2022
Risposto: MathWorks Support Team
il 24 Feb 2022
I am looking to run a compiled and deployed Web App on my MATLAB Web App Server instance. This app will need to establish a connection with the MS SQL database via the JDBC driver and the database uses Windows Authentication by default. What steps are necessary in order to successfully connect to the database from the deployed Web App session?
Note that I am able to connect to the database successfully from MATLAB running on the server machine. It is only when I compile the code that I run into errors.
Risposta accettata
MathWorks Support Team
il 4 Feb 2022
To download the JDBC driver (mssql-jdbc-x.x.x.jrex.jar) and the authentication DLL (mssql-jdbc_auth-x.x.x.x64.dll referenced in this solution, select the "Microsoft SQL Server JDBC" option at this link:
1. On the development machine, add the JDBC Driver and the authentication DLL as "required files" when compiling the Web App CTF archive.
2. On the server machine, install the JDBC driver JAR file and add it to the MATLAB Runtime Java class path.
Edit the file "classpath.txt" inside your MATLAB Runtime installation's "toolbox\local" directory and add the absolute location of the JAR file to the end of the list. Note that the path you enter must include the name of the JAR file as well. You must restart the server instance for this change to take effect.
If you have not done this, you will encounter a "JDBC Driver not found" error.
3. Install the authentication DLL on the server machine and add it to the MATLAB Runtime Java library path.
Edit the file "librarypath.txt" inside your MATLAB Runtime installation's "toolbox\local" directory and add the absolute location of the folder containing the DLL to the list
(only the path to the folder containing the DLL, not the path to the DLL itself)
. You must restart the server instance for this change to take effect.
If you have not done this, you will encounter a "JDBC Driver not configured for integrated authentication" error.
4. Configure your Web App Launcher service to start under a Windows user that has been given access to the database.
Because you are trying to use Windows Authentication to establish a connection to the database, the login information for the requested connection is obtained from the Windows user profile that is attempting to connect. That means, when running the app on your Web App Server, the Windows user that is running the Web App is the one that will give its login information to attempt a database connection. You will need to configure the MATLAB Web App Launcher service to run under a Windows user that has access to the database. You can do this using one of the following methods:
a. Give the default Web App Launcher service user (MwWebAppWorkerR2021b) access to your SQL database
b. Configure the user that the Web App Launcher service runs under. For information on how to do this when creating a new server, see this documentation link:
Otherwise, if you want to configure an existing Web App server, see this MATLAB Answers post:
If you have not done this, you will receive a "JDBC Driver Error: Login failed." error.
0 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!