2013-04-03 128 views
0

我使用本教程中的代碼片段來連接到MSSQL darabase。無法連接到MSSQL數據庫2012

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"); 
    } 

究竟是什麼例外,如何解決它的原因是什麼?

+1

錯誤消息表明在遠程主機上沒有進程偵聽。你能否驗證是否有進程正在偵聽,例如通過在遠程主機上執行'netstat -an'並查看端口1434是否實際打開? – mthmulders

+0

yeap。在結果列表中沒有該端口的本地或外部地址。我通過找到正確的端口進行連接,您可以將它作爲答案發布.. :) – lakshman

回答

5

如果沒有監聽,SQL Server不接受TCP連接。您必須配置SQL Server才能這樣做。 This article解釋瞭如何爲給定實例啓用服務器網絡協議。

1

我有同樣的錯誤,我修改了SQL Server Express的屬性。 MyComputer>管理> SQL Server服務> SQL Server登錄>內置帳戶>從網絡服務到本地系統。