title: Getting "db server closed connection" when connecting with MS SQL server
body: <p>In my android app, I am connecting MS SQL server using a jtds jar file. below is the code for my connection class:</p>
  
  <pre><code>public class ConnectionClass {
      String ip = "192.168.1.26";
  
      //String ip = "IRFAN//SQLPOS";
  
      String classs = "net.sourceforge.jtds.jdbc.Driver";
      String db = "Sysit";
      String un = "sa";
      String password = "123";
  
      @SuppressLint("NewApi")
      public Connection CONN() {
          StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                  .permitAll().build();
          StrictMode.setThreadPolicy(policy);
          Connection conn = null;
          String ConnURL = null;
          try {
  
              Class.forName(classs);
              ConnURL = "jdbc:jtds:sqlserver://" + ip + ";"
                      + "databaseName=" + db + ";user=" + un + ";password="
                      + password + ";";
              Log.d("connection url",ConnURL);
              conn = DriverManager.getConnection(ConnURL);
          } catch (SQLException se) {
              Log.e("ERRO", se.getMessage());
          } catch (ClassNotFoundException e) {
              Log.e("ERRO", e.getMessage());
          } catch (Exception e) {
              Log.e("ERRO", e.getMessage());
          }
          Log.d("connection variable",conn.toString());
          return conn;
      }
  }
  </code></pre>
  
  <p>I am able to connect to database by creating the object of connectinclass and calling the <code>CONN()</code>. I am connecting to database the same way in 2 or 3 activities. but after few clicks in the app, the database connection is not working.</p>
  
  <p>It shows following error in the LogCat:</p>
  
  <blockquote>
    <p>E/ERRO: I/O Error: DB server closed connection.</p>
  </blockquote>