Search code examples
javasqlsql-serverjdbc

SQLServerException: Login failed for user 'sa'. ClientConnectionId:


I'm trying to connect throw JDBC such like:

      Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
      Connection conn = DriverManager.getConnection(SQL_URL, SQL_USER , SQL_PASS);

But when i execute `getConnection(); I get this error:

    com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'. ClientConnectionId:04a4bf33-3489-4279-a6f8-a4da8b7ee567
           at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:254)[...]

I'm sure the login is on the instance>Security>logins and set with SQL Server Authentication but it is still failing.


Solution

  • You probably need to enable SQL Server Authentication:

    Propierties

    sql server authentication

    Please mind: after applying this settings you need to restart your server.