title: MS SQL Server and JDBC: closed connection
body: <p>Im getting </p>
  
  <blockquote>
    <p><strong>I/O Error: DB server closed connection.</strong></p>
  </blockquote>
  
  <p>while connecting to MS SQL server 2008 from java code .</p>
  
  <hr>
  
  <p>SQL server is in mixed mode and its in local machine.My connection string is
  <strong>jTDS</strong> </p>
  
  <blockquote>
    <p><strong>jdbc:jtds:sqlserver://machineName:1433;databaseName=DB;integratedSecurity=true</strong></p>
  </blockquote>
  
  <hr>
  
  <p>stack trace is</p>
  
  <blockquote>
    <p>java.sql.SQLException: I/O Error: DB server closed connection.
        at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2311)
        at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:610)
        at net.sourceforge.jtds.jdbc.ConnectionJDBC2.(ConnectionJDBC2.java:345)
        at net.sourceforge.jtds.jdbc.ConnectionJDBC3.(ConnectionJDBC3.java:50)
        at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at com.app.hibernate.test.(test.java:22)
        at com.app.hibernate.test.main(test.java:53)
    Caused by: java.io.IOException: DB server closed connection.
        at net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.java:848)
        at net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket.java:727)
        at net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStream.java:466)
        at net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.java:103)
        at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2206)
        ... 8 more
    Exception in thread "main" java.lang.NullPointerException
        at com.app.hibernate.test.db(test.java:36)
        at com.app.hibernate.test.main(test.java:54)</p>
  </blockquote>
  
  <p><strong>JDBC Driver</strong></p>
  
  <blockquote>
    <p>String url ="jdbc:sqlserver://machine:1433;instance=SQLEXPRESS;databaseName=db";</p>
  </blockquote>
  
  <p>stacktrace</p>
  
  <blockquote>
    <p>com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'username'.
        at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:156)
        at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:240)
        at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:78)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2636)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2046)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2034)
        at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4003)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1550)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1207)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(SQLServerConnection.java:1054)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:758)
        at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at com.app.hibernate.test.(test.java:22)
        at com.app.hibernate.test.main(test.java:53)
    Exception in thread "main" java.lang.NullPointerException
        at com.app.hibernate.test.db(test.java:36)
        at com.app.hibernate.test.main(test.java:54)</p>
  </blockquote>