title: Not able to access one database in SQL Server using Java
body: <p>I have an SQL Server 2012 edition. I have two databases on this server. One of these databases named BANKTEST was restored from a backup a few months ago. I have recently restored another database named NEWBANK. </p>
  
  <p>The following is the java program which I had written to access NEWBANK</p>
  
  <pre><code>package com.example.myproject.client;
  
  import java.sql.DriverManager;
  import java.sql.Connection;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  
  public class ConnectMSSQL {
  
      public static void main(String[] args) throws SQLException, ClassNotFoundException {
          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  
          Connection conn = DriverManager.getConnection("jdbc:sqlserver://127.0.0.1;user=sa;password=sa123;Database=NEWBANk");
          System.out.println("test");
          Statement sta = conn.createStatement();
          String Sql = "select TOP 10 CodeType from D001002";
          ResultSet rs = sta.executeQuery(Sql);
          while (rs.next()) {
              System.out.println(rs.getString("CodeType"));
          }
      }
  }
  </code></pre>
  
  <p>Unfortunately, I am getting an error which I have listed below</p>
  
  <pre><code>&gt; Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database "NEWBANK" requested by the login. The login failed. ClientConnectionId:69c57dd7-38b1-413c-b8ea-8d53824f74e1
      at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
      at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:254)
      at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:84)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2908)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2234)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220)
      at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326)
      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.example.myproject.client.ConnectMSSQL.main(ConnectMSSQL.java:13)
  </code></pre>
  
  <p>If I replace the name of the database with BANKTEST, I do not get any errors. Can someone advice me on this?</p>
  
  <p>Regards</p>
  
  <p>Sachin</p>