This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Connect to MS SQl Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connect to MS SQl Server" Watch "Connect to MS SQl Server" New topic

Connect to MS SQl Server

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
I am trying to connect to SQL server Express DB installed on localbox from my java program. I am using jtds driver and the sample code is below.

When I try to run the program, I get an error saying "java.sql.SQLException: Network error IOException: Connection refused: connect"

If I use

I get an error "java.sql.SQLException: Server localhost has no instance named SQLEXPRESS."

I have the driver jar in class path and my VM args are "-Djava.library.path=C:\jtds-1.2.5-dist\x64\SSO" pointing to the NTLM dll.
I am able to connect to the DB from the MS SQL Server Management Studio.

Can somebody help me to solve this?

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Any help on this?
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

The first message invariably means that you don't have a server listening at the specified port. So do you have your database server running on the same computer where your application is running? (That's what "localhost" means.) And is it listening at port 1433? I'm not sure about the Express version, but by default SQL Server is configured to not listen for TCP/IP connections. It expects to be contacted by some proprietary Windows method which isn't supported in Java. So check that configuration and turn on the TCP/IP option if it's not already on.
I agree. Here's the link:
subject: Connect to MS SQl Server
Similar Threads
java.sql.SQLException: I/O Error: DB server closed connection.
Problems regarding MS JDBC Driver and JTDS-JDBC Connectivity for MS SQL Server 2000
problem connecting to sql database using jtds driver
unable to connect to MS SQL server 2000
jtds error while connecting to MS SQL server 2008