Results 1 to 17 of 17
Like Tree3Likes
  • 1 Post By gimbal2
  • 1 Post By SurfMan
  • 1 Post By Tolls

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

  1. #1
    Jack_Tauson_Sr is offline Senior Member
    Join Date
    Nov 2011
    Posts
    114
    Rep Power
    0

    Default 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:sqlserver://XX.XX.X.XXX:1433;databaseName=MyDB;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
    Last edited by Jack_Tauson_Sr; 04-25-2014 at 11:51 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    Could be this?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    936
    Rep Power
    2

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    Instead of the Mickysoft driver, you might want to check out this one: jTDS JDBC Driver. It's rock solid, fast and very stable. We haven't used any other driver since SQLServer v7.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    Quote Originally Posted by SurfMan View Post
    Instead of the Mickysoft driver, you might want to check out this one: jTDS JDBC Driver. It's rock solid, fast and very stable. We haven't used any other driver since SQLServer v7.
    Okay but that's not an answer to this question, with the Microsoft reference driver it must also be possible to make it work ;)

    Switching to another driver is a last resort that requires intensive integration testing before you can sell it to your boss (or rather: it should require that).
    SurfMan likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    936
    Rep Power
    2

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    Quote Originally Posted by gimbal2 View Post
    Okay but that's not an answer to this question, with the Microsoft reference driver it must also be possible to make it work ;)

    Switching to another driver is a last resort that requires intensive integration testing before you can sell it to your boss (or rather: it should require that).
    True. Just handing out alternatives here.

    As for the solution:
    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
    You never told us if that worked or not.

    One common error is that SQLServer Authentication is not enabled, only Windows Authentication.
    gimbal2 likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    I wish I worded my previous comment with a little more tact, but I see you got the intended meaning ;)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    936
    Rep Power
    2

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    Quote Originally Posted by gimbal2 View Post
    I wish I worded my previous comment with a little more tact, but I see you got the intended meaning ;)
    I know my pappenheimers :)
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    Ha ha ha :) I actually had to look that one up.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    Jack_Tauson_Sr is offline Senior Member
    Join Date
    Nov 2011
    Posts
    114
    Rep Power
    0

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    In the SQL Management Studio, in the Server Property Window, I have the following Server Authentication
    mode selected instead of only Windows Authentication mode.

    SQL Server and Windows Authentication mode


    And yes "1) Tried Logging with the "sa" user name and password within the SQL Server Management Console using SQL Server Management studio " did work out for me.

    Quote Originally Posted by SurfMan View Post
    True. Just handing out alternatives here.

    As for the solution:

    You never told us if that worked or not.

    One common error is that SQLServer Authentication is not enabled, only Windows Authentication.

  10. #10
    Jack_Tauson_Sr is offline Senior Member
    Join Date
    Nov 2011
    Posts
    114
    Rep Power
    0

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    Good Catch !!

    I have been using JDK 1.8. Do you think that I should not use "sqljdbc4.jar" anymore?
    P.S: I am not allowed to make any changes to SQL Server 2008

    Quote Originally Posted by Tolls View Post
    Could be this?
    Last edited by Jack_Tauson_Sr; 04-30-2014 at 08:20 AM.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    Use jTDS.
    Or at least try it with that driver.
    If it works it gives you (along with the link I posted) some ammunition to push to use a different driver.
    gimbal2 likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #12
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    I can get behind that reasoning, but its a hard one to sell though. "Yeah the Microsoft driver to connect to the Microsoft database does not work, we need to use a third party one". If I had to sell that to my manager, he'd shake his head and tell me to read the documentation again. Is there not some source that explains in more words why jTDS is preferred over the reference driver?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    That very link I gave.
    If it is that problem, which isn't confirmed as it relates to specific versions of 2008.
    If the OP is using one of those problem versions then the task is to either patch the version, as specified there, or to change the driver. Actually, re-reading that report, I'm not sure it's the driver. It sounds like it's SQL Server itself that has the problem.

    So the OP needs to check the version and patches applied to their SQL Server 2008 installation, and see if it is one of the ones with this problem. If so, then the obvious fix is to patch the DB. It's a Microsoft bug, as that page admits.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #14
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    Quote Originally Posted by Tolls View Post
    That very link I gave.
    *slithers back into the shadows*
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    Quote Originally Posted by gimbal2 View Post
    *slithers back into the shadows*
    I have to admit, it's not the most obvious link I've ever added to a thread...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  16. #16
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    ... and it also does not mention to swap out the driver as a solution, but I do like to slither in shadows ;)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Keep on getting Login failed for user 'sa' despite using correct login credential

    Well, I did originally misread it as a driver problem...:)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 6
    Last Post: 10-22-2012, 02:12 PM
  2. Send login credentials to applet in html
    By spooky in forum Java Applets
    Replies: 2
    Last Post: 05-14-2010, 03:50 AM
  3. SQL server 2005 - Login failed message
    By pbaudru in forum JDBC
    Replies: 15
    Last Post: 02-10-2010, 11:03 AM
  4. Replies: 0
    Last Post: 06-25-2008, 12:41 PM
  5. Login user name - for all platforms.
    By Eranga in forum Advanced Java
    Replies: 0
    Last Post: 03-17-2008, 05:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •