【问题标题】:How to connect spring boot to sql server management studio如何将spring boot连接到sql server management studio
【发布时间】:2021-10-29 21:23:15
【问题描述】:

所以,我想将 spring boot 连接到 sql server management studio,以练习 crud 操作,但是当我尝试它时,我得到一个错误: enter image description here

所以,我添加了依赖项: enter image description here

我添加了属性: enter image description here

这是我的 sql 服务器: enter image description here

在这里,我创建了一个名为 product 的数据库: enter image description here

我还启用了 TCP/IP:enter image description here

我也将 TCP 端口设置为 1433:enter image description here

但是我仍然遇到同样的错误,谁能解释一下是什么问题以及我该如何解决?

P.s我还没有写任何代码,我只是用spring initilizer做了一个空项目,现在我只想将spring boot连接到sql server(所以我只是运行一个空的演示应用程序)

我也尝试通过编写java代码连接到sql server,但它也失败了:

【问题讨论】:

  • 对我来说看起来像防火墙配置。该错误是“连接被拒绝”,通常与阻止连接的防火墙有关。我建议你检查你的防火墙设置
  • 我应该在哪里查看防火墙设置?我应该改变什么?
  • 您好,您可以张贴实际的文本/代码,而不是图片吗?例如。在您的帖子中复制粘贴application.properties 的内容,而不仅仅是添加图像。它让我们所有人都更轻松。
  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: java sql-server spring spring-boot


【解决方案1】:

您的连接字符串错误。对于 Express,您需要在末尾添加实例名称。看看这个问题:JDBC connection Url for SQLServer express R2

【讨论】:

  • 我不明白我应该用什么替换我的连接字符串你能告诉我吗?
  • 应该类似于jdbc:sqlserver://localhost/SQLEXPRESS;databaseName=product
  • 反斜杠,而不是正斜杠,用于分隔机器和实例名称。
【解决方案2】:

您的连接 URL 中可能缺少一些内容,例如:

  • 端口号
  • 实例名称
  • 基本身份验证

将 URL 更改为如下所示:

jdbc:sqlserver://DESKTOP-7HI4O73;user=Givexa;password=yourPassWord

【讨论】:

    【解决方案3】:

    在您的application.properties 文件中尝试将spring.datasource.url 属性更改为:

    spring.datasource.url=jdbc:sqlserver://localhost\\SQLEXPRESS:1433;databaseName=product
    

    【讨论】:

    • 使用端口号或实例名称,不能同时使用。
    猜你喜欢
    • 2021-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-14
    • 2020-08-14
    • 2013-11-02
    • 1970-01-01
    相关资源
    最近更新 更多