0

I've added Ubuntu 20.04 under AD Domain controller and have installed MsSQL Server on Ubuntu machine.

My sqlcmd localhost works perfectly with windows authentication

$ sqlcmd -S localhost
1> select @@version
2> GO
                                                                                                                                                                                                                                                                                                            
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Microsoft SQL Server 2019 (RTM-CU10) (KB5001090) - 15.0.4123.1 (X64) 
    Mar 22 2021 18:10:24 
    Copyright (C) 2019 Microsoft Corporation
    Developer Edition (64-bit) on Linux (Ubuntu 20.04.2 LTS) <X64>                                                                                                      

(1 rows affected)
1> 

Now, I'm trying to connect it with Simple Java code as

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
 
/**
 * This program demonstrates how to establish database connection to Microsoft
 * SQL Server.
 *
 */
public class JdbcSQLServerConnection {
 
    public static void main(String[] args) {
 
        Connection conn = null;
 
        try {
 
            String dbURL = "jdbc:sqlserver://170.18.xx.xx:1433;integratedSecurity=true";
            String user = "sa";
            String pass = "*****************";
            conn = DriverManager.getConnection(dbURL, user, pass);
            if (conn != null) {
                DatabaseMetaData dm = (DatabaseMetaData) conn.getMetaData();
                System.out.println("Driver name: " + dm.getDriverName());
                System.out.println("Driver version: " + dm.getDriverVersion());
                System.out.println("Product name: " + dm.getDatabaseProductName());
                System.out.println("Product version: " + dm.getDatabaseProductVersion());
            }
 
        } catch (SQLException ex) {
            ex.printStackTrace();
        } finally {
            try {
                if (conn != null && !conn.isClosed()) {
                    conn.close();
                }
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }
    }
}

I ran this source code as

java -cp mssql-jdbc-8.4.1.jre8.jar:sqljdbc4.jar:. -Djava.library.path=mssql-jdbc_auth-8.4.1.x64.dll JdbcSQLServerConnection

It throws exception as Caused by: java.lang.UnsatisfiedLinkError: no mssql-jdbc_auth-8.4.1.x64 in java.library.path

I found below few unanswered threads but not sure if they have added their machines under any DC

  1. no mssql-jdbc_auth-8.4.1.x64 in java.library.path
  2. no mssql-jdbc auth-8.4.1.x64 in java.library.path on linux
  3. https://github.com/microsoft/mssql-jdbc/issues/1453
Swapnil Kotwal
  • 5,418
  • 6
  • 48
  • 92
  • The DLL has to be in the `java.library.path`, **not** the classpath. *Hint:* The `java.library.path` is by default the same as the `PATH` environment variable. – Andreas Apr 21 '21 at 07:10
  • but `.DLL` will work on `Ubuntu` machines? – Swapnil Kotwal Apr 21 '21 at 07:12
  • Oops, good point. On Linux, you need the `.so` file, not the `.dll` file. – Andreas Apr 21 '21 at 07:14
  • Yeah.. any idea where will I get it for this `MsSQL Server` Windows authentication? I'm not getting it. – Swapnil Kotwal Apr 21 '21 at 07:16
  • This is not related to your error message but... in your dbURL choose either an instance name, `jdbc:sqlserver://170.18.xx.xx\\MSSQLSERVER;`, or a port, `jdbc:sqlserver://170.18.xx.xx:1433;`, not both. Since you already know the port number use that. – AlwaysLearning Apr 21 '21 at 07:16
  • 1
    I don't think there is an `auth` library for Linux. – Andreas Apr 21 '21 at 07:17
  • Yes, I used the only `Port No` in JDBC URL, it is working fine. But, what you advise for `authenticating` it on `Ubuntu` machine – Swapnil Kotwal Apr 21 '21 at 07:22

1 Answers1

0

Seems like this is long requested answer, I finally able to connect to MsSQL Server 2019 installed on Ubuntu 20.04

what all I need is to use below syntax of DB URL and I don't need to pass any DLL or auth file.

"jdbc:sqlserver://172.18.44.171:1433;integratedSecurity=true;authenticationScheme=javaKerberos;authentication=NotSpecified";

I simply ran

java -cp mssql-jdbc-8.4.1.jre8.jar:. JdbcSQLServerConnection

Please refer this discussion here Connect To SQL Server With Windows Authentication From A Linux Machine Through JDBC

Swapnil Kotwal
  • 5,418
  • 6
  • 48
  • 92