I have an instance of sql server, which can be connected either by windows authentication or by sql auhthentication:
public static void main(String[] args) {
Connection conn = null;
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://localhost:1434;databasename=Test;";
String userName = "sa";
String password = "paquito";
Statement stmt;
try{
Class.forName(driver);//.newInstance();
conn = DriverManager.getConnection(url,userName,password);
stmt = conn.createStatement();
System.out.println("conectado = ");
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
That connection works without problems, let's go to windows authentication:
public static void main(String[] args) {
Connection conn = null;
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://localhost:1434;databasename=Test;integratedSecurity=true";
String userName = "paco";
String password = "";
Statement stmt;
try{
Class.forName(driver);//.newInstance();
conn = DriverManager.getConnection(url,userName,password);
stmt = conn.createStatement();
System.out.println("conectado = ");
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
and I get the second error:
com.microsoft.sqlserver.jdbc.SQLServerException: No se puede abrir la base de datos "Test" solicitada por el inicio de sesión. Error de inicio de sesión. ClientConnectionId:577da72f-f0d4-4ac6-abab-243f0f84d0e3
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:217)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:279)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:99)
NOTE: from the sql management I can connect in 2 ways.