title: SQL Server Database Connection Errors
body: <p>We're trying to, essentially, connect a database to a hall/worker management program custom built in Java. This is a multiple-module project and our database team decided to use SQL Server as base for their management.</p>
  
  <p>Unfortunately, this proved problematic resulting in a deluge of errors that we're entirely not sure how to fix. After searching through the Stack, similar problems arose but were either not solved and simply 'started working' on their own or 'fixed' by moving away from SQL Server, which we can't do either.</p>
  
  <p>Without further ado, here's the problem itself. The program operates on all data properly, as it was debugged in a 'testmode' wherein values are fed directly into the code without the use of an external database. The real problem arose when trying to put the two and two together.</p>
  
  <p>Firstly, the connection ports for localhost proved problematic. Using port 1433 we failed to even establish a connection, and even unlocking the port changed nothing. After moving to 1434, we managed to establish a connection of sorts.</p>
  
  <p>Here's the error-block regarding port 1433, if it's necessary:</p>
  
  <pre><code>The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
  at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
  at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:241)
  at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2243)
  at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:491)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1309)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
  at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at com.j256.ormlite.jdbc.JdbcConnectionSource.makeConnection(JdbcConnectionSource.java:252)
  at com.j256.ormlite.jdbc.JdbcConnectionSource.getReadWriteConnection(JdbcConnectionSource.java:184)
  at com.j256.ormlite.jdbc.JdbcConnectionSource.getReadOnlyConnection(JdbcConnectionSource.java:170)
  at com.j256.ormlite.stmt.StatementExecutor.buildIterator(StatementExecutor.java:243)
  at com.j256.ormlite.stmt.StatementExecutor.query(StatementExecutor.java:197)
  at com.j256.ormlite.stmt.StatementExecutor.queryForAll(StatementExecutor.java:118)
  at com.j256.ormlite.dao.BaseDaoImpl.queryForAll(BaseDaoImpl.java:239)
  at controler.AdminRoomControler.getListRoomEquipmentData(AdminRoomControler.java:51)
  at gui.panel.ReservationRoomPanel.reloadData(ReservationRoomPanel.java:57)
  at gui.panel.ReservationRoomPanel.initialize(ReservationRoomPanel.java:82)
  at gui.panel.ReservationRoomPanel.&lt;init&gt;(ReservationRoomPanel.java:40)
  at gui.frame.ApplicationFrame.initialize(ApplicationFrame.java:58)
  at gui.frame.ApplicationFrame.&lt;init&gt;(ApplicationFrame.java:37)
  at main.Program$1.run(Program.java:22)
  at java.awt.event.InvocationEvent.dispatch(Unknown Source)
  at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
  at java.awt.EventQueue.access$200(Unknown Source)
  at java.awt.EventQueue$3.run(Unknown Source)
  at java.awt.EventQueue$3.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
  at java.awt.EventQueue.dispatchEvent(Unknown Source)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.run(Unknown Source)
  </code></pre>
  
  <p>Upon changing the port to 1434, we were greeted with another problem. For some reason, SQL Server responds to our connection with a Prelogin Handshake problem we have absolutely no idea how to fix. The errors are as follows:</p>
  
  <pre><code>sty 11, 2014 5:32:02 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: 0a8f83b1-ce25-48c1-8796-c2c5c7d080b7 Prelogin error: host localhost port 1434 Error reading prelogin response: Software caused connection abort: recv failed ClientConnectionId:0a8f83b1-ce25-48c1-8796-c2c5c7d080b7
  sty 11, 2014 5:32:02 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: 982a07f7-0cbd-417f-8bcb-47eebe6b4524 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:982a07f7-0cbd-417f-8bcb-47eebe6b4524
  sty 11, 2014 5:32:02 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: 9c136851-d172-4b98-8722-16941642d14a Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:9c136851-d172-4b98-8722-16941642d14a
  sty 11, 2014 5:32:03 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: bc3db9f2-6d56-43bd-9145-051dc418d8b9 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:bc3db9f2-6d56-43bd-9145-051dc418d8b9
  sty 11, 2014 5:32:04 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: 93c0fd9c-925d-40d9-af4e-35be3f3ec0d4 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:93c0fd9c-925d-40d9-af4e-35be3f3ec0d4
  sty 11, 2014 5:32:05 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: cb32d339-0c63-4549-8821-61b2818c9548 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:cb32d339-0c63-4549-8821-61b2818c9548
  sty 11, 2014 5:32:06 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: 5c63f908-8019-48ac-9b4e-0b9a4c29e6e6 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:5c63f908-8019-48ac-9b4e-0b9a4c29e6e6
  sty 11, 2014 5:32:07 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: ce8945a8-1fe7-40b8-a7c9-331f263be084 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:ce8945a8-1fe7-40b8-a7c9-331f263be084
  sty 11, 2014 5:32:08 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: a0ed799f-471e-4496-8fb5-6f2599faa45f Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:a0ed799f-471e-4496-8fb5-6f2599faa45f
  sty 11, 2014 5:32:09 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: f35803a2-7e46-4163-a9db-08977c78fd63 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:f35803a2-7e46-4163-a9db-08977c78fd63
  sty 11, 2014 5:32:10 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: 182e2bf0-9ad6-40e6-b767-ab6bf7173929 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:182e2bf0-9ad6-40e6-b767-ab6bf7173929
  sty 11, 2014 5:32:11 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: 7d71a9ec-c22b-4247-8bd2-540e75470e80 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:7d71a9ec-c22b-4247-8bd2-540e75470e80
  sty 11, 2014 5:32:12 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: 9a739139-241f-47c4-bfe8-bb3a1cbe3c18 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:9a739139-241f-47c4-bfe8-bb3a1cbe3c18
  sty 11, 2014 5:32:13 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: d53915f6-5419-4bd0-883f-5c25a12d5678 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:d53915f6-5419-4bd0-883f-5c25a12d5678
  sty 11, 2014 5:32:14 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: 8eaec619-d01a-4138-bb06-44cdc8a08fe9 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:8eaec619-d01a-4138-bb06-44cdc8a08fe9
  sty 11, 2014 5:32:15 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: 4c176172-9ff5-479a-b39a-40e026da9e16 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:4c176172-9ff5-479a-b39a-40e026da9e16
  sty 11, 2014 5:32:16 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: 6b9ab775-5845-4b11-ad25-9cef7b56f041 Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:6b9ab775-5845-4b11-ad25-9cef7b56f041
  sty 11, 2014 5:32:17 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
  WARNING: ConnectionID:1 ClientConnectionId: 04ef0517-4410-4d63-947c-d349ed4684ad Prelogin error: host localhost port 1434 Error reading prelogin response: Connection reset ClientConnectionId:04ef0517-4410-4d63-947c-d349ed4684ad
  com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset ClientConnectionId:04ef0517-4410-4d63-947c-d349ed4684ad
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1654)
      at com.microsoft.sqlserver.jdbc.TDSChannel.read(IOBuffer.java:1789)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(SQLServerConnection.java:1424)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1319)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
      at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at com.j256.ormlite.jdbc.JdbcConnectionSource.makeConnection(JdbcConnectionSource.java:252)
      at com.j256.ormlite.jdbc.JdbcConnectionSource.getReadWriteConnection(JdbcConnectionSource.java:184)
      at com.j256.ormlite.jdbc.JdbcConnectionSource.getReadOnlyConnection(JdbcConnectionSource.java:170)
      at com.j256.ormlite.stmt.StatementExecutor.buildIterator(StatementExecutor.java:243)
      at com.j256.ormlite.stmt.StatementExecutor.query(StatementExecutor.java:197)
      at com.j256.ormlite.stmt.StatementExecutor.queryForAll(StatementExecutor.java:118)
      at com.j256.ormlite.dao.BaseDaoImpl.queryForAll(BaseDaoImpl.java:239)
      at controler.AdminRoomControler.getListRoomEquipmentData(AdminRoomControler.java:51)
      at gui.panel.ReservationRoomPanel.reloadData(ReservationRoomPanel.java:57)
      at gui.panel.ReservationRoomPanel.initialize(ReservationRoomPanel.java:82)
      at gui.panel.ReservationRoomPanel.&lt;init&gt;(ReservationRoomPanel.java:40)
      at gui.frame.ApplicationFrame.initialize(ApplicationFrame.java:58)
      at gui.frame.ApplicationFrame.&lt;init&gt;(ApplicationFrame.java:37)
      at main.Program$1.run(Program.java:22)
      at java.awt.event.InvocationEvent.dispatch(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$200(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)
  </code></pre>
  
  <p>Finally, we've encountered a typographic problem where the name of column in the file and in the database was mismatched. Correcting that, unfortunately, caused even more error to appear. To add insult to injury, sometimes it does not even detect the mismatch error, so we're completely at loss here.</p>
  
  <p>Here's our code used to hook the database up:</p>
  
  <pre><code>package database;
  
  import java.sql.SQLException;
  
  import POJO.Administrator;
  import POJO.Equipment;
  import POJO.Event;
  import POJO.Guest;
  import POJO.Personnel;
  import POJO.Room;
  
  import com.j256.ormlite.dao.Dao;
  import com.j256.ormlite.dao.DaoManager;
  import com.j256.ormlite.jdbc.JdbcConnectionSource;
  import com.j256.ormlite.support.ConnectionSource;
  
  
  public class DbManager  {
  
      // Proper db address should be placed here.
      private final String DATABASE_URL = "jdbc:sqlserver://localhost:1434;databaseName=IO;integratedSecurity=true;";
  
      private ConnectionSource connectionSource;
  
      public Dao&lt;Administrator,Integer&gt; administratorDao;
      public Dao&lt;Equipment,Integer&gt; equipmentDao;
      public Dao&lt;Event,Integer&gt; eventDao;
      public Dao&lt;Guest,Integer&gt; guestDao;
      public Dao&lt;Personnel,Integer&gt; personnelDao;
      public Dao&lt;Room,Integer&gt; roomDao;
  
      public DbManager() throws SQLException
      {
          connectionSource = new JdbcConnectionSource(DATABASE_URL);
          administratorDao = DaoManager.createDao(connectionSource, Administrator.class);
          equipmentDao = DaoManager.createDao(connectionSource, Equipment.class);
          eventDao = DaoManager.createDao(connectionSource, Event.class);
          guestDao = DaoManager.createDao(connectionSource, Guest.class);
          personnelDao = DaoManager.createDao(connectionSource, Personnel.class);
          roomDao = DaoManager.createDao(connectionSource, Room.class);
      }
  
      @Override
      protected void finalize() throws Throwable
      {
          connectionSource.close();       
          super.finalize();
  
      }
  }
  </code></pre>
  
  <p>We are completely out of ideas and really, anything that doesn't concern either completely rewriting the database from SQL Server to something else will be of aid. Thank you in advance!</p>