0

我在本教程中使用代码片段连接到 MSSQL darabase。

http://www.java-tips.org/other-api-tips/jdbc/how-to-connect-microsoft-sql-server-using-jdbc.html

但是当我运行程序时,我得到了这个错误。

     java.sql.SQLException: Network error IOException: Connection timed out: connect
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:410)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
    at java.sql.DriverManager.getConnection(DriverManager.java:579)
    at java.sql.DriverManager.getConnection(DriverManager.java:221)
    at DB.dbConnect(Test.java:28)
    at Test.main(Test.java:12)
Caused by: java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:307)
    at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:257)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:311)
    ... 6 more

我的连接网址是

db.dbConnect(
     "jdbc:jtds:sqlserver://CSLK-PT12DB:1434/R8_JBOSS_MSSQL_Archived_Migrated_Beta","spider3","spider3");
    }

此异常的原因是什么以及如何解决?

4

2 回答 2

5

如果没有监听,SQL Server 不接受 TCP 连接。您必须配置 SQL Server 才能执行此操作。本文介绍如何为给定实例启用服务器网络协议。

于 2013-04-03T09:16:09.450 回答
1

我遇到了同样的错误,我通过更改 SQL Server Express 属性来修复它。MyComputer > Manage > SQL Server Services > SQL ServerLog on > built-in account > 从网络服务到本地系统。

于 2016-09-29T16:00:46.163 回答