Sql server Can';t通过Microsoft SQL Server 2012 JDBC驱动程序连接到SQL Server
这很奇怪。我在运行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 client 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. 你知道为什么微软的驱动程序失败了,但是jTDS在远程主机上成功了吗?Microsoft one中的jTDS URL中唯一缺少的信息是实例名(“SQLEXPRESS”)。是的,我已经尝试了使用和不使用实例名的Microsoft URL Mac主机上的Java版本为:Sql server Can';t通过Microsoft SQL Server 2012 JDBC驱动程序连接到SQL Server,sql-server,macos,jdbc,virtualbox,jtds,Sql Server,Macos,Jdbc,Virtualbox,Jtds,这很奇怪。我在运行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
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
理论上,您还需要jTDS连接字符串中的实例名称(例如,追加“instance=SQLEXPRESS”)——但我不熟悉jTDS,我可能是错的,但是如果您没有设置该名称,并且正在连接,那么您可能正在连接其他东西 您在上面显示了带有IP地址的jTDS连接字符串,以及带有服务器名“winny”的Microsoft连接字符串(jdbc:sqlserver://winny\SQLEXPRESS:1433;databaseName=vha)--您尝试过IP地址吗?(jdbc:sqlserver://192.168.99.132\SQLEXPRESS:1433;数据库名称=vha) 我通常尝试的事情:
路德,谢谢你的回复。请参阅下面我的评论。我做了你建议的一切,一切都正常。还有其他想法吗?从表面上看,jtds驱动程序正常工作而Microsoft驱动程序不正常,这似乎表明Microsoft驱动程序的网络代码中存在缺陷……我还确认了jtds驱动程序可以连接实例名,也可以不连接实例名。请参见实例名称。简单地粘贴代码并不是一个好的答案。虽然这可以解决老年退休金问题,但对他们理解问题或您的解决方案毫无帮助。
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";