R2DBC-MSSQL how to connect to a database

620 Views Asked by At

I am trying to connect to my local SQL Server with R2DBC, unfortunately, I do not know where I am going wrong, I have a lot of experience with R2DBC, I use it all the time with other databases but this is my first time with MSSQL, below is my MSSQL ConnectionFactorythat is failing:

    @Bean
override fun connectionFactory(): ConnectionFactory {
    val options = builder()
        .option(DRIVER, "sqlserver")
        .option(HOST, properties.host)
        .option(PORT, properties.port.toInt())
        .option(USER, properties.username)
        .option(PASSWORD, properties.password)
        .option(DATABASE, properties.database)
        .option(SSL, false)
        .build()

    val connectionFactory = ConnectionFactories.get(options)
    val configuration = ConnectionPoolConfiguration.builder(connectionFactory)
        .maxIdleTime(Duration.ofMillis(1000))
        .maxSize(20)
        .build()

    connectionPool = ConnectionPool(configuration)
    return ProxyConnectionFactory.builder(connectionPool)
        .build()
}

My properties

  com:
  #Application database
  database:
    host: PC_NAME\SQLEXPRESS
    port: 51306
    database: app_database
    username: user
    password: pass

When I run my application I get the error below:

    09:02:40.151 [reactor-tcp-nio-1] DEBUG reactor.pool.SimpleDequePool - failed to warm up extra resource 9/9: java.net.UnknownHostException: Failed to resolve 'PC_NAME\SQLEXPRESS' after 4 queries 
    09:02:40.153 [parallel-2] ERROR reactor.core.publisher.Operators - Operator called default onErrorDropped
    reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.transaction.CannotCreateTransactionException: Could not open R2DBC Connection for transaction; nested exception is java.net.UnknownHostException: Failed to resolve 'PC_NAME\SQLEXPRESS' after 4 queries 
    Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open R2DBC Connection for transaction; nested exception is java.net.UnknownHostException: Failed to resolve 'PC_NAME\SQLEXPRESS' after 4 queries 

I do not understand where I am going wrong, I can confirm that I have enabled TCP and shown below enter image description here

And enabled remote connection on my server instance

enter image description here

Does anyone know how this works?

0

There are 0 best solutions below