May 242010
 

Error : Trying to connect to SQL Server 2005 Express version using jTDS 1.2.4 driver in my Java Application and getting “java.sql.SQLException: Network error IOException: Connection refused: connect SQL Express” error.

Answer from http://jtds.sourceforge.net/faq.html#connectionRefused

The “Connection refused” exception is thrown by jTDS when it is unable to connect to the server. There may be a number of reasons why this could happen:

  1. The server name is misspelled or the port number is incorrect.
  2. SQL Server is not configured to use TCP/IP. Either enable TCP/IP from SQL Server’s Network  Utility app or have jTDS connect via named pipes (see the URL format for information on how to do this).
  3.  There is a firewall blocking port 1433 on the server.

 

If you found the above answers are too simple, hope the detail steps below on how to enable TCP/IP,  adding TCP/IP port and using TCP/IP port help:

  1. Open the Configuration Manager:
    Start -> Microsoft SQL Server 2005 -> Configuration Tools -> SQL Server Configuration Manager
  2. Enable the TCP/IP: from the left hand tree choose:
    SQL Server 2005 Network Configuration-> Protocol for SQLEXPRESS-> TCP/IP
    Right click and enable it.
  3. Double click the TCP/IP and click on the “IP Addresses” Tab
  4. Adding TCP/IP port : Enter TCP Port value to 1433 then click apply
  5. Restart SQL Server: from the left hand tree, choose:
    SQL Server 2005 Services -> SQL Server (SQLEXPRESS) -> right click and restart.
  6. Open the Surface Area Configuratioin:
    Start -> Microsoft SQL Server 2005 -> Configuration Tools -> SQL Server 2005 Surface Area Configuration
  7. Select the Surface Area Configuration for services and Connections link.
  8. Using TCP/IP : from the left hand tree, choose:
    SQLEXPRESS -> Database engine -> Remote Connections
    Choose “Using TCP/IP only” under “Local and remote connections” on the right hand panel.
  9. Restart SQLEXPRESS: from the left hand tree, choose:
    SQLEXPRESS -> Database Engine -> Service
    Click on “Stop” button and then “Start” button.