0

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?

Alfa
  • 95
  • 6
  • Use the provided client tool (SSMS) to confirm you can connect to `PC_NAME\SQLEXPRESS`. Also confirm that this r2dbc process is running on the same machine as your SQLEXPRESS install. – Nick.Mc Jun 30 '22 at 07:52
  • The screenshot of your TCP/IP Properties is showing "Enabled: No" for all of the addresses visible in the scroll area. Do you actually have any ports enabled, such as the "IPAll" address, or have you only enabled the protocol? Also after changing any protocol settings in SQL Server Configuration Manager you need to restart the SQL Server service for the changes to take effect. – AlwaysLearning Jun 30 '22 at 09:59
  • @Nick.McDermaid Yes, I can connect. The process is running just fine, `PC_NAME` is the same PC I am building the app on. – Alfa Jun 30 '22 at 10:17
  • @AlwaysLearning you could be right. I have IP1 - IP9, which one do I enable? – Alfa Jun 30 '22 at 10:20

0 Answers0