0

This flutter package uses a jdbc driver to send a connection request to SQL Server. On the SQL Server side, it does SQL authentication using the username and password it received. Instead of using SQL Server auth, is it possible to pass over Windows credentials and have SQL Server authenticate using that? Below is the code used in this package to connect.

private suspend fun connectToDB(call: MethodCall, result: Result) {
        try {
            val ip: String = call.argument<String>("ip").toString()
            val port: String = call.argument<String>("port").toString()
            val Classes = "net.sourceforge.jtds.jdbc.Driver"
            val database = call.argument<String>("databaseName").toString()
            val username = call.argument<String>("username").toString()
            val password = call.argument<String>("password").toString()
            val timeout =  call.argument<Int>("timeout")
            val url = "jdbc:jtds:sqlserver://$ip:$port/$database"

            Class.forName(Classes)
            DriverManager.setLoginTimeout(timeout!!.toInt())
            connection = DriverManager.getConnection(url, username, password)
            result.success(true)
        } catch (e: Throwable) {
            result.error("ERROR", e.message.toString(), null)
        } catch (e: ClassNotFoundException) {
            result.error("ClassNotFoundException", e.message.toString(), null)
        } catch (e: SQLException) {
            result.error("SQLException", e.message.toString(), null)
        } catch (e: Exception) {
            result.error("Exception", e.message.toString(), null)
        }
    }
TheMortiestMorty
  • 421
  • 2
  • 4
  • 12
  • Please read: [JDBC vs Web Service for Android](https://stackoverflow.com/q/15853367/295004) Also realize that you would need an Android compatible JDBC driver that has support for Windows Authentication. I am not aware of any for the reasons in the prior link. – Morrison Chang Aug 30 '23 at 22:55

0 Answers0