【发布时间】:2014-03-26 18:38:45
【问题描述】:
我正在使用 tomee,JPA 并在下面找到配置:
tomee.xml:
<?xml version="1.0" encoding="UTF-8"?>
<tomee>
<Resource id="dataSource" type="DataSource">
JdbcDriver com.microsoft.sqlserver.jdbc.SQLServerDriver
JdbcUrl jdbc:sqlserver://******:1433;databaseName=******
UserName ******
Password ******
JtaManaged true
</Resource>
</tomee>
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="app">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>dataSource</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
</properties>
</persistence-unit>
</persistence>
这在我的本地运行良好。但是当我尝试将我的应用程序部署到 Dev Linux 服务器时,我得到了这个异常WARN: HHH000342: Could not obtain connection to query metadata : The TCP/IP connection to the host ******, port 1433 has failed. Error: "null. 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.".
唯一的区别是 localhost 是 windows 机器,而 dev server 是 Linux 机器。据我所知,除了主机名之外,连接字符串不需要更改。
我也尝试使用数据库服务器 IP 地址而不是主机名。现在服务器卡在这一点上:INFO: HHH000130: Instantiating explicit connection provider:org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
请提出您的建议。
【问题讨论】:
-
检查你的 1433 端口是否为外部连接打开
-
是的,我可以从本地成功连接。该问题仅在 Dev Linux 服务器上存在。
-
从 linux ping 数据库服务器
-
我可以 ping 通服务器。然后我尝试使用 IP 地址而不是主机名。现在它停留在这一点:INFO:HHH000130:实例化显式连接提供程序:org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
-
做了一些搜索,您收到的错误消息似乎与 url 中的错误有关:stackoverflow.com/questions/16610832/… 它是 localhost 与远程的事实也是这里的一个因素,所以可能不是与它是linux有什么关系。我只有一个通用的建议,就是把jdbc-driver改成jtds,jtds.sourceforge.net,例如config见openejb.979440.n4.nabble.com/…
标签: java sql-server jpa jdbc apache-tomee