0

I am trying to do this tutorial and when I got to the hibernate part, I get this errors:

java.sql.SQLException: Network error IOException: Connection refused: connect
    at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:436)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataS
ource.java:146)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(Wrap
perConnectionPoolDataSource.java:195)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(Wrap
perConnectionPoolDataSource.java:184)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourceP
oolManager.acquireResource(C3P0PooledConnectionPool.java:200)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.ja
va:1086)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAc
quiresWithinLockOnSuccess(BasicResourcePool.java:1073)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.j
ava:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(Basic
ResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolA
synchronousRunner.java:648)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.SocksSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.jav
a:288)
    at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:251)
    at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:331)
    ... 10 more

Here is the hibernate.cfg.xml part of accessing the database:

<!--Database connection settings-->
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="connection.url">jdbc:jtds:sqlserver://localhost:1433;databaseName=MyTut1db</property>
<property name="connection.username">sop1</property>
<property name="connection.password">myPW1</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>

The user sop1 was created in MS SQL Server 2012 Express edition as:

CREATE LOGIN sop1
    WITH PASSWORD = 'myPW1';
USE MyTut1db;
GO
CREATE USER sop1 FOR LOGIN sop1;
GO 

The database properties are in the figure below: db propr

I have inabled the TCP-IP from MS SQL Server Configuration Manager (TCP Port is 1433), but the problem still persists.

I have also closed the antivirus for a while.

I am asking for some help: What else can it be? How do I verify the user? How do I know that localhost:1433 is the right server?

2
  • These kind of things always result from existing problems that SHOULD be considered, but are totally ignored because nobody wants to be responsible for fixing them. In this case I would find it a huge red flag that you have to go to stackoverflow in stead of being able to ask someone close to you, or check documentation like a "how to setup your development environment" or whatever you're dealing with here. Commented Jan 14, 2014 at 13:33
  • I think I don't understand you and you don't understand me. Reading it again, I was making a huge assumption - that you are doing this at work and not at home. Commented Jan 14, 2014 at 14:05

3 Answers 3

4

I would check things following these steps:

  • Ensure that SQL Server is up and running. Check your running services to see if SQL Server service is up.

  • I would check the SQL Server Configuration Manager to see if the TCP/IP communication is enabled.

  • I would check my firewall settings. Perhaps something is in the way between SQL Server and the client.

  • I would check if another application from the same client can connect to the same server. Then I would check the connection string differences.

  • If all of the above were playing correctly, then I would check the privileges on the specific SQL Server, on the specific database, for the account I am trying to connect with. Allow everyone to use this database as a first step to check if it is an account-permissions problem.

Hope I helped!

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

4 Comments

That was a typing problem that is not solving my problem, i have corrected it an it is the same
I have allwed the eclipse and java from firewall, I have started sqlsrvr, and TCP/IP was turned on and no changes. How do I check the last two steps?
i have found it here... but now I am getting other error :(
And the last one was because of ntlmauth.dll
2

localhost will always be the server your Java is running on - it's saying "Talk back to the same machine".

If your database is hosted on a different server, you need to put that server name in the configuration.

Comments

1

Please the check the following

  1. Click Start >Programs -> Microsoft Sql Server 2008 R2 -> Configuration Tools -> Sql Server Configuration Manager
  2. Click Sql Server Network Configuration

  3. Click Protocols for SQLExpress

  4. Double click TCP/IP and click IP adrress tab

  5. Go to the end till you see IP ALL

  6. Ensure that you see port number 1433 is configured under TCP Port under IPALL header.

  7. If not configured, enter 1433 port and click Apply.

  8. You need to restart the MS sql server and try now and it should work.

Hope this will solve it.

Comments

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.