R2DBC-MSSQL如何连接到数据库

发布于 2025-02-11 14:56:58 字数 2398 浏览 1 评论 0原文

我正在尝试使用R2DBC连接到本地SQL Server,不幸的是,我不知道我的误解,我对R2DBC有很多经验,我一直在其他数据库中使用它,但这是我第一次使用MSSQL,以下是我的MSSQL ConnectionFactory失败:

    @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()
}

我运行应用程序时我的属性

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

我在下面得到错误:

    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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文