这很奇怪。我在运行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 guest虚拟机的IPv4地址为192.168.99.132,Windows防火墙已关闭。
我为Windows和Mac下载了Microsoft SQL Server 2012 JDBC驱动程序以及Squirrel SQL客户端3.4.0。当我在Windows 7客户操作系统上运行Squirrel时,我可以使用“winny”,“localhost”或“192.168.99.132”的客户机名称通过Microsoft JDBC驱动程序连接到SQL Server(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 guest虚拟机时的堆栈跟踪:
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
答案 0 :(得分:0)
理论上你还需要jTDS连接字符串中的实例名称(例如附加“; instance = SQLEXPRESS”) - 但我并不熟悉jTDS,我可能错了,但如果你没有设置那个,那么你那么你可能正在连接其他东西吗?
您使用IP地址显示上面的jTDS连接字符串,使用服务器名称“winny”显示您的jTDS连接字符串(jdbc:sqlserver:// winny \ SQLEXPRESS:1433; databaseName = vha) - 您是否尝试过IP地址? (JDBC:SQLSERVER://192.168.99.132 \ SQLEXPRESS:1433;的databaseName = VHA)
我经常尝试的事情:
因为您可以使用jTDS从Mac客户端进行连接,所以您应该能够完成所有这三项工作,但值得仔细检查。
你也可以尝试在服务器上硬编码端口1433(从空白处更改) - 也许存在另一个SQL实例?另请参阅http://support.microsoft.com/kb/287932
以下是我经常会遇到的一些步骤,也许这会有所帮助:
答案 1 :(得分:0)
Step 1: Download jtds.jar from http://sourceforge.net/projects/jtds/files/
Step 2: Add the jar into eclipse or any IDE.
Step 3:
String driver="net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
String connString="jdbc:jtds:sqlserver://127.0.0.1:1433/database_name;encrypt=false;user=sa;password=yourpassword;integratedSecurity=true;instance=SQLEXPRESS;";
String username="sa";
String password="yourpassword";
OR
String connString="jdbc:jtds:sqlserver://192.168.1.198:1433/database_name;encrypt=false;user=sa;password=yourpassword;";
String username="sa";
String password="yourpassword";