sql-server - Hibernate 在连接到远程 SQL Server 时出现问题
问题描述
我有一个使用 Hibernate 连接到 SQL Server 2017 的网页。我已经在服务器为 localhost 的机器上以及远程安装了许多提到的应用程序。
现在我面临的情况是 Hibernate 无法建立与远程服务器的连接(单击“登录”按钮后显示堆栈跟踪页面)。我已经检查了所有可能的内容,但找不到错误。所有这一切都在发生,而我完全有能力从托管网站的同一台计算机(使用 Tomcat)连接到该服务器,同时使用 Microsoft SQL Server Management 和 Windows 服务,这意味着可以访问远程服务器!
在我看来,问题在于我能找到的唯一区别是这个安装和以前的安装:远程服务器的 IP 链接包含一个额外的参数,即\DB_COMPANY,如下(来自 hibernate.cfg):
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:sqlserver://10.150.10.37\DB_COMPANY:1433;databaseName=COMPANY</property>
<property name="hibernate.connection.username">company</property>
<property name="hibernate.connection.password">Company</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
我得到的印象是 Hibernate 无法处理这个额外的参数,并且通过 MS SQL 管理和提到的服务进行测试,\DB_COMPANY
补充是访问远程服务器所必需的。我尝试了不同的斜线组合,但总是出现某种错误。如果是反斜杠,那就难过Error calling Driver#connect
;如果正斜杠,消息The TCP/IP connection to the host 10.150.10.37/DB_COMPANY, port 1433 has failed. Error: "10.150.10.37/DB_COMPANY. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall."
那么这是问题所在吗?我该如何解决?如果不是,那是什么?随时询问任何额外的信息。
解决方案
好吧,我终于找到了问题所在。它不是 int eh\DB_COMPANY
部分,而是端口。无论出于何种原因,当 Windows 服务能够与该端口通信时,网站却不能。
推荐阅读
- c++ - 结构/方法不起作用
- java - 创建通用对象的缓存
- html - 如何获得彩色输入标签?
- amazon-web-services - 使用 CloudWatch 安排 API Gateway 请求?
- python - 仅 1 个标量的张量板摘要标量错误
- node.js - 要使用新的解析器,请将选项 { useNewUrlParser: true } 传递给 MongoClient.connect
- amazon-web-services - aws 圣杯忽略代理配置
- python - 如何在 Dict{key:List} 中找到最小值?
- javascript - jQuery未定义的ajax函数
- haskell - 在使用 Haskell 实现 Eratosthenes 筛法中,为什么 3,5,7.. 的倍数没有从列表中删除?