lakshman
lakshman

Reputation: 2741

can't connect to MSSQL database 2012

I used code snippet in this tutorial to connect to MSSQL darabase.

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

but when I run the program, I got this error.

     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

my connection url is

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

what is the reason for this exception and how to solve it?

Upvotes: 0

Views: 5568

Answers (2)

I had the same error, and I fixed it by changed SQL Server Express properties. MyComputer > Manage > SQL Server Services > SQL ServerLog on > built -in account > from Network service to Local System.

Upvotes: 1

mthmulders
mthmulders

Reputation: 9705

If nothing is listening, SQL Server isn't accepting TCP connections. You'll have to configure SQL Server to do so. This article explains how to enable a server network protocol for a given instance.

Upvotes: 5

Related Questions