This guide explains how to set up MS SQL Server for Java applications with Windows Authentication, ensuring you can connect to your database using integratedSecurity
mode.
- Windows OS: 7, 8, 10, or 11.
- MS SQL Server: Installed and running.
- Java: Installed (JDK/JRE).
- Admin rights on your computer to modify system files and firewall settings.
- Visit the official Microsoft JDBC Driver for SQL Server page.
- Select a version that matches your Java runtime (e.g., 12.6.3 or similar).
- Download the
.zip
file.
- Unzip the downloaded file to a folder of your choice.
- Inside the extracted folder:
- Locate the
.jar
file (e.g.,mssql-jdbc-12.6.3.jre8.jar
). - Locate the
auth
folder (containsauth.dll
).
- Locate the
- Option 1: Add the
.jar
file to your project’s classpath manually. - Option 2 (Recommended): Use Maven:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>12.6.3.jre8</version> <!-- Adjust version as needed -->
</dependency>
- From the
auth
folder, copy the appropriateauth.dll
(x64 or x86 depending on your system). - Paste it into your Java installation’s
bin
directory:- Example:
C:\Program Files\Java\jdk-17\bin\
- Example:
- Open SQL Server Configuration Manager (search in Start Menu).
- Navigate to:
- SQL Server Network Configuration > Protocols for MSSQLSERVER.
- Enable TCP/IP.
- Right-click TCP/IP, select Properties, and:
- IP Addresses Tab:
- Set TCP Port to 1433 for IPAll and other relevant IPs.
- Ensure 127.0.0.1 is listed for local connections.
- IP Addresses Tab:
- Open Control Panel > System and Security > Windows Defender Firewall > Advanced Settings.
- Add a New Inbound Rule:
- Type: Port
- Protocol: TCP
- Port: 1433
- Allow the connection.
- Apply the rule to Domain, Private, and Public.
Use the following format in your Java code to connect using Windows Authentication:
String connectionUrl =
"jdbc:sqlserver://localhost:1433;databaseName=YourDatabaseName;"
+ "integratedSecurity=true;"
+ "trustServerCertificate=true;";
integratedSecurity=true;
enables Windows Authentication.trustServerCertificate=true;
allows self-signed certificates (for development).
- Always verify that your firewall and network configurations allow SQL Server traffic.
- If using Maven, ensure the driver version matches your Java version.
- If experiencing authentication issues, double-check that the
auth.dll
is placed correctly and matches your architecture (x64/x86).
- Fork this repository.
- Create a new branch:
git checkout -b fix/configure-mssql
. - Add your changes.
- Commit your changes:
git commit -m "Added clear README for configuring MS SQL Server on Windows"
. - Push to the branch:
git push origin fix/configure-mssql
. - Submit a Pull Request.