0

I am using sqljdbc4.jar in the Build path of eclipse project. I am trying to connect to SQL Server 2008 in a java program

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
           "databaseName=sis;user=sample;password=sample;";
        connection = DriverManager.getConnection(connectionUrl);

But I am getting the following error. The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect

I tried the following

  • Firewall off

  • Enabled TCP/IP in SQL Server configuration manager --> CLient protocols

  • SQL Server browser service is also running Please let me know what other things should I try.

Thanks

2
  • 2
    Did you try connecting to the DB Server instance using an SQL Server Management Studio? Commented Sep 2, 2011 at 10:19
  • Yes I did tried that. I am able to do it. There are some settings which we need to do with regards to SQL Server. Commented Sep 2, 2011 at 10:27

1 Answer 1

1

Firewall off which way, this way??? open/enable port localhost:1433

run cmd and paste

netsh firewall set portopening protocol = TCP port = 1433 
name = SQLPort mode = ENABLE scope = SUBNET profile = CURRENT 

2/ change Sql Server authentication from

Windows authe... to Sql Server and Windows authentification (Mixed mode)

3) your version is SQL Server 2008 or SQL Server 2008 Express, if Express, then search on downloaded package (contains excelent help inc examples) how to connect Express on Localhost, there is difference localhost\sqlexpress

here and here and here

4) no idea how to connected, there are TCP/IP and Names Pipes too

EDIT:

5) in Management Studio you have to add new User (SQL autenthification) and assign to the decision Database (whatever or Model too) is there ??? aren't you

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I have SQL Server 2008 Enterprise Edition. 1) I added an exception for port 1433 in the firewall 2) Authentication is Mixed mode 3) the user has been added on the server . I can see it under Security 4) Also, the tried the CMD comment u gave. Even by doing all this the problem is not being resolved..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.