Friday, April 25, 2014

Keep on getting Login failed for user 'sa' despite using correct login credentials




I am simply trying to test my connection with SQL Server 2008 as follows:






Java Code:






public class ForJDBC {


public static void main(String[] args) {




try{

Connection conn = DriverManager.getConnection("jdbc:http://sqlserver10.11.0.225:1433;databaseName=Alerts;user=sa;password=mypassword");

if(conn != null){

System.out.println("Connection is Successfull");
}

}
catch(SQLException ex){

ex.printStackTrace();
}




}
}




But I keep on getting the following exception:



Java Code:






[COLOR="#FF0000"]com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'. ClientConnectionId:96f7d048-9734-4fd8-8216-21231d89b2e6
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
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(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at forjdbc.ForJDBC.main(ForJDBC.java:35)[/COLOR]




When I connect to MySQL 5.5, it works fine.




Troubleshooting Steps I have followed:




1) Tried Logging with the "sa" user name and password within the SQL Server Management Console



using SQL Server Management studio




2) I have sqljdbc4.jar in my Source Package folder of Netbeans 7.4




3) Updated to Java 8







No comments:

Post a Comment