这很奇怪。我在运行 VirtualBox 4.2.6 的 Mac OS X 10.7.5 64 位主机上。我有一个运行 Microsoft SQL Server Express 2012 的带有桥接网络的 Windows 7 SP1 来宾(64 位)。我将 SQL Server 配置为在端口 1433 上使用 TCP/IP,而不是动态端口(设置为空白,而不是 0)。Windows 7 来宾的 IPv4 地址为 192.168.99.132,并且 Windows 防火墙已关闭。
我下载了 Microsoft SQL Server 2012 JDBC 驱动程序以及适用于 Windows 和 Mac 的 Squirrel SQL 客户端 3.4.0。当我在 Windows 7 来宾操作系统本身上运行 Squirrel 时,我可以通过 Microsoft JDBC 驱动程序使用“winny”、“localhost”或“192.168.99.132”的来宾计算机名称(JDBC URL 像jdbc:sqlserver://winny\SQLEXPRESS:1433;databaseName=vha)。但是,当我尝试从 Mac 主机上运行的 Squirrel 连接到 SQL Server 时,出现异常(请参阅下面的堆栈跟踪)。
这是奇怪的部分。如果从 Mac 主机上,我使用 jTDS SQL Server 驱动程序(版本 1.2.7,因为我使用的是 JDK6,所以不能使用 jTDS 1.3.0 - 该版本仅是 JDK7),我会立即连接JDBC URL jdbc:jtds:sqlserver://192.168.99.132:1433/vha。
任何想法为什么 Microsoft 驱动程序失败但 jTDS 从远程主机成功?Microsoft 中的 jTDS URL 中唯一缺少的信息是实例名称(“SQLEXPRESS”)。是的,我尝试了带有和不带有实例名称的 Microsoft URL。
Mac 主机上的 Java 版本为:
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)
Windows 7 客户机上的 Java 版本为:
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)
从 Mac 主机连接到 Windows 7 客户机时的堆栈跟踪:
java.util.concurrent.ExecutionException: java.lang.RuntimeException: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.99.132, 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.".
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:232)
at java.util.concurrent.FutureTask.get(FutureTask.java:91)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.awaitConnection(OpenConnectionCommand.java:132)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.access$100(OpenConnectionCommand.java:45)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand$2.run(OpenConnectionCommand.java:115)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.RuntimeException: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.99.132, 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.".
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.executeConnect(OpenConnectionCommand.java:171)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.access$000(OpenConnectionCommand.java:45)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand$1.run(OpenConnectionCommand.java:104)
... 6 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.99.132, 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.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:241)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2243)
at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:491)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1309)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager.getConnection(SQLDriverManager.java:133)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.executeConnect(OpenConnectionCommand.java:167)
... 8 more