148

I have created login account on my localhost\sql2008 Server (Eg. User123)

Mapped to Database (default)

Authentication Mode on SQL Server is set to both (Windows and SQL)

But login to SQL Server fails with following message (for User123)

Note: Have checked multiple time that UserName / Password are typed in correctly

Error Details:

Login failed for user 'User123' (Net.SqlClient Data Provider)

Server Name : localhost\sql2008 Error Number: 18456 Severity : 14 State : 1 Line Number : 65536

any help on this please.

6
  • 1
    Test both the sql and windows authentication access through SqlServer Management Console for the user and see if you can access with the above account. What data provider and connection string are you using?
    – Joe Pitz
    Commented Mar 19, 2010 at 3:51
  • 1
    Am trying to login in SSMS and it throws above error.
    – Sreedhar
    Commented Mar 19, 2010 at 3:52
  • 1
    You can login as admin account?
    – Joe Pitz
    Commented Mar 19, 2010 at 4:06
  • Login as admin and check your eventlog. The reason for the error should be listed there. Look under the management folder
    – Joe Pitz
    Commented Mar 19, 2010 at 4:14
  • Alternate that worked for me was stackoverflow.com/questions/28090747/… Commented Oct 17, 2016 at 20:51

9 Answers 9

382

You need to enable SQL Server Authentication:

  1. In the Object Explorer, right click on the server and click on "Properties"

DBMS Properties dialog

  1. In the "Server Properties" window click on "Security" in the list of pages on the left. Under "Server Authentication" choose the "SQL Server and Windows Authentication mode" radio option.

SQL Server Authentication dialog

  1. Restart the SQLEXPRESS service.
7
  • 3
    Why should this work if OP explicitly states that "Authentication Mode on SQL Server is set to both (Windows and SQL)"? Commented Dec 18, 2014 at 9:02
  • 5
    This answer is redundant and not useful for the question. The OP already established that "Authentication Mode on SQL Server is set to both (Windows and SQL)".
    – Manachi
    Commented Oct 27, 2015 at 23:27
  • 1
    IMPORTANT: RIGHT-CLICK RESTART INSIDE SQL MANAGEMENT STUDIO'S OBJECT EXPLORER... NOT SQL CONFIGURATION MANAGER. Commented Dec 22, 2015 at 18:01
  • So I guess the question is, how do we set up a user and password? I can select an existing windows-user, and see this user is connected, and verify the password works for 'windows' - but when I try it's user/pass combination to connect to the Database, I get "login failed for user ...." Does the SQL Server have separate passwords which need to be configured separately? If so, where?
    – JosephK
    Commented Sep 8, 2016 at 12:19
  • one quick note....I closed out ssms and re opened and couldn't get it to work...it took me a minute to realize I actually needed to right click on the instance and restart it. just in case anyone else thinks they restarted but didn't actually....
    – pauliec
    Commented Sep 20, 2021 at 14:11
56

By default login failed error message is nothing but a client user connection has been refused by the server due to mismatch of login credentials. First task you might check is to see whether that user has relevant privileges on that SQL Server instance and relevant database too, thats good. Obviously if the necessary prvileges are not been set then you need to fix that issue by granting relevant privileges for that user login.

Althought if that user has relevant grants on database & server if the Server encounters any credential issues for that login then it will prevent in granting the authentication back to SQL Server, the client will get the following error message:

Msg 18456, Level 14, State 1, Server <ServerName>, Line 1
Login failed for user '<Name>'

Ok now what, by looking at the error message you feel like this is non-descriptive to understand the Level & state. By default the Operating System error will show 'State' as 1 regardless of nature of the issues in authenticating the login. So to investigate further you need to look at relevant SQL Server instance error log too for more information on Severity & state of this error. You might look into a corresponding entry in log as:

2007-05-17 00:12:00.34 Logon     Error: 18456, Severity: 14, State: 8.
or

2007-05-17 00:12:00.34 Logon     Login failed for user '<user name>'.

As defined above the Severity & State columns on the error are key to find the accurate reflection for the source of the problem. On the above error number 8 for state indicates authentication failure due to password mismatch. Books online refers: By default, user-defined messages of severity lower than 19 are not sent to the Microsoft Windows application log when they occur. User-defined messages of severity lower than 19 therefore do not trigger SQL Server Agent alerts.

Sung Lee, Program Manager in SQL Server Protocols (Dev.team) has outlined further information on Error state description:The common error states and their descriptions are provided in the following table:

ERROR STATE       ERROR DESCRIPTION
------------------------------------------------------------------------------
2 and 5           Invalid userid
6                 Attempt to use a Windows login name with SQL Authentication
7                 Login disabled and password mismatch
8                 Password mismatch
9                 Invalid password
11 and 12         Valid login but server access failure
13                SQL Server service paused
18                Change password required


Well I'm not finished yet, what would you do in case of error:

2007-05-17 00:12:00.34 Logon     Login failed for user '<user name>'.

You can see there is no severity or state level defined from that SQL Server instance's error log. So the next troubleshooting option is to look at the Event Viewer's security log [edit because screen shot is missing but you get the

idea, look in the event log for interesting events].

7
  • 1
    Thanks will look and see how it goes
    – Sreedhar
    Commented Mar 19, 2010 at 4:24
  • 1
    dead link please consider revising Commented Jul 5, 2012 at 20:15
  • 11
    The superior answer below this one should be chosen, not this. Commented Sep 6, 2012 at 19:19
  • 6
    @void.pointer the OP already established that "Authentication Mode on SQL Server is set to both (Windows and SQL)". So the post below has no relevance to this question.
    – Manachi
    Commented Oct 27, 2015 at 23:27
  • Viewing the event log led me to the following error: Login failed for user 'mdm'. Reason: An attempt to login using SQL authentication failed. Server is configured for Windows authentication only. [CLIENT: <local machine>]. Thanks.
    – Kenci
    Commented Aug 22, 2017 at 10:29
51

I had this same problem, however mine was because I hadn't set the Server authentication to "SQL Server and Windows Authentication mode" (which you had) I just wanted to mention it here in case someone missed it in your question.

You can access this by

  • Right click on instance (IE SQLServer2008)
  • Select "Properties"
  • Select "Security" option
  • Change "Server authentication" to "SQL Server and Windows Authentication mode"
  • Restart the SQLServer service
    • Right click on instance
    • Click "Restart"
3
  • 7
    I spent like two hours because I was not getting that I need to RESTART the whole server. This is just insane that a restart is needed for such thing. Microsoft has no limits to the crapware they spit out. Commented Jul 6, 2012 at 15:39
  • 1
    This is also vital answer for why cannot connect to Amazon EC2 instance which SQL server installed on it. Commented Sep 10, 2013 at 4:43
  • Check this post to fix windows authentication mode doesn't work.
    – Shaiju T
    Commented Feb 1 at 16:10
22

You can access this by

Right click on instance (IE SQLServer2008)
Select "Properties"
Select "Security" option
Change "Server authentication" to "SQL Server and Windows Authentication mode"
Restart the SQLServer service
    Right click on instance
    Click "Restart"

Just for anyone else reading this: This worked for me on 2012 SQL Server too. Thanks

2
  • 1
    Thank you this was perfect, straight to the point.. the accepted answer is filled with good info but this is what worked for me.
    – Tony
    Commented Aug 24, 2014 at 3:07
  • 4
    This can't work for OP since he mentioned that "Authentication Mode on SQL Server is set to both (Windows and SQL)". Commented Dec 18, 2014 at 9:03
3

After enabling "SQL Server and Windows Authentication mode"(check above answers on how to), navigate to the following.

  1. Computer Mangement(in Start Menu)
  2. Services And Applications
  3. SQL Server Configuration Manager
  4. SQL Server Network Configuration
  5. Protocols for MSSQLSERVER
  6. Right click on TCP/IP and Enable it.

Finally restart the SQL Server.

2

None of the solutions will work for you if you do not restart the SQL Server.

Find the SQLServerManager13.msc

Then in SQL Server Services section select SQL Server and restart it.

Or

Select you server in the Object Explorer menu in MS SQL Server Management Studio.

Right click on it and restart

2

After spending a long time and trying every suggestion on every page, this solved my problem:

[server name] > Security > Logins > [Login Name] > Right Click > Properties > Status > SQL Server authentication

There is a checkbox Login is locked out. It was checked and preventing me from login. I unchecked the checkbox and my problem was solved.

2

try using this connection string

Server=ServerName;Database=DbName;Trusted_Connection=SSPI;MultipleActiveResultSets=true;TrustServerCertificate=true
1

The correct solution to the problem is to make sure SQL server authentication is turned on for your SQL Server.

Not the answer you're looking for? Browse other questions tagged or ask your own question.