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:
- The server name is misspelled or the port number is incorrect.
- 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).
- 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:
- Open the Configuration Manager:
Start -> Microsoft SQL Server 2005 -> Configuration Tools -> SQL Server Configuration Manager - 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. - Double click the TCP/IP and click on the “IP Addresses” Tab
- Adding TCP/IP port : Enter TCP Port value to 1433 then click apply
- Restart SQL Server: from the left hand tree, choose:
SQL Server 2005 Services -> SQL Server (SQLEXPRESS) -> right click and restart. - Open the Surface Area Configuratioin:
Start -> Microsoft SQL Server 2005 -> Configuration Tools -> SQL Server 2005 Surface Area Configuration - Select the Surface Area Configuration for services and Connections link.
- 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. - Restart SQLEXPRESS: from the left hand tree, choose:
SQLEXPRESS -> Database Engine -> Service
Click on “Stop” button and then “Start” button.