无法连接到MSSQL数据库2012

时间:2013-04-03 09:02:14

标签: java sql-server-2012

我在本教程中使用了代码片段来连接到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");
    }

这个例外的原因是什么以及如何解决?

2 个答案:

答案 0 :(得分:5)

如果没有正在侦听,则SQL Server不接受TCP连接。您必须配置SQL Server才能这样做。 This article解释了如何为给定实例启用服务器网络协议。

答案 1 :(得分:1)

我遇到了同样的错误,我通过更改的SQL Server Express属性修复了它。 我的电脑&gt;管理&gt; SQL Server服务&gt; SQL Server登录&gt;内置帐户&gt;从网络服务到本地系统。