简体   繁体   English

开发服务器上的JDBC SQL Server连接错误

[英]jdbc sql server connection error on dev server

I am using tomee, JPA and find below the configuration: 我正在使用tomee,JPA,并在下面找到配置:

tomee.xml: 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: 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>

This is working fine on my local. 这在我的本地计算机上工作正常。 But when I tried to deploy my application to Dev Linux server, I am getting this exception 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.". 但是,当我尝试将应用程序部署到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.". 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.".

The only difference is localhost is windows machine and dev server is Linux machine. 唯一的区别是localhost是Windows计算机,而dev服务器是Linux计算机。 As far as I know for this there are no changes required in connection string except the host name. 据我所知,除了主机名外,连接字符串中不需要进行任何更改。

I also tried with DB server IP address instead of host name. 我也尝试使用DB服务器IP地址而不是主机名。 Now server is stuck at this point: INFO: HHH000130: Instantiating explicit connection provider:org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider 现在服务器卡在了这里: INFO: HHH000130: Instantiating explicit connection provider:org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider

Please give your suggestions. 请提出您的建议。

I tried with jtds and it worked. 我尝试使用jtds并成功。 So I think there might be some issues if we use sql jdbc driver in linux. 因此,我认为如果在Linux中使用sql jdbc驱动程序,可能会出现一些问题。

There was one more issue. 还有一个问题。 When I tried with jtds, I got this exception: java.lang.UnsupportedClassVersionError: net/sourceforge/jtds/jdbc/Driver : Unsupported major.minor version 51.0 . 当我尝试使用jtds时,遇到了以下异常: java.lang.UnsupportedClassVersionError: net/sourceforge/jtds/jdbc/Driver : Unsupported major.minor version 51.0 My local JDK was 1.7 and Dev server JDK was 1.6. 我的本地JDK是1.7,而开发服务器JDK是1.6。 And I tried to deploy the war generated from my local to Dev server. 然后,我尝试将本地产生的战争部署到Dev服务器。 Once I changed server JDK to 1.7 this issue also got resolved. 将服务器JDK更改为1.7后,此问题也得到解决。

There's a Windows service that runs on the database server called the “SQL Server Browser” that needed to be restarted. 需要在数据库服务器上运行一个名为“ SQL Server Browser”的Windows服务,该服务需要重新启动。 The service was listed as running, but it wasn't responding to queries. 该服务被列为正在运行,但未响应查询。 As soon as we restarted this service everything started working again. 重新启动此服务后,一切都会重新开始。 Here's some more information on this service. 这是有关此服务的更多信息。

http://msdn.microsoft.com/en-us/library/hh510203.aspx http://msdn.microsoft.com/en-us/library/hh510203.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM