login failed error sql server – SQLSERVERLEARNER https://sqlserverlearner.com LEARN SQL SERVER ONLINE Fri, 09 Dec 2011 08:14:41 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 sql server error 18456 – Login failed for user https://sqlserverlearner.com/2011/12/09/microsoft-sql-server-error-18456/ https://sqlserverlearner.com/2011/12/09/microsoft-sql-server-error-18456/#respond Fri, 09 Dec 2011 08:14:41 +0000 https://sqlserverlearner.azurewebsites.net/2011/12/09/microsoft-sql-server-error-18456/ Microsoft sql server error 18456 – Login failed for the user

When you try to connect to SQL Server you get the error 18456.

Error Message:
Cannot connect to Servername.
ADDITIONAL INFORMATION:
Login failed for user ‘username’. (Microsoft SQL Server, Error: 18456)

Additional details of the error when connecting from sql server management studio would be like this:

Server Name: Servername
Error Number: 18456
Severity: 14
State: 1
Line Number: 65536

Reasons for the error:
User does not have access on the server
Provided user name is wrong
Provided Password is Wrong
Using windows login credentials for SQL Server authentication
Login for the user is disabled
Login was successfull but access to the server failed
Problems with SQL Service
Password for the user has to be changed
User does not have access to perform the specified acton on the server, Only has limited access
User does not have previlages to access the specific database, agent service etc

The exact actual reason behind this error can be seen in the Server Error log by the server administrator.

Also the error at a high level can be sorted out by the value of state in the error message.

According to MSDN Following is the list of error descriptions according to the state of the error: (SQL Server error 18456 error state list)

State Description Of The State Error
state 2 User ID is not valid.
state 5 User ID is not valid.
state 6 An attempt was made to use a Windows login name with SQL Server Authentication.
state 7 Login is disabled, and the password is incorrect.
state 8 The password is incorrect.
state 9 Password is not valid.
state 11 Login is valid, but server access failed.
state 12 Login is valid login, but server access failed.
state 18 Password must be changed.
state 23 SQL Service is shutting down.
state 38 User does not have access to the database.
Other States Internal Server Error

Resolution/Fix for sql server error 18456:
Contact the system administrator for help regarding this
Accoding to the state of the error, choose the possible solution.
Change password if the state is 18
For states 8 and 9 try to login with the correct password
For state 6 use windows authentication instead of sql server authentication
For state 2 and 5 use the correct userid to login

SA login failure error 18456:
Frequent SA login failures occur when the authentication mode of SQL Server is changed form windows authentication to SQL Server authentication.
In such cases the following error occurs:
Login failed for user ‘sa’

Use the following script to enable SA login with a password:
[sql]
ALTER LOGIN sa ENABLE
GO
–Change the newpassword value below
ALTER LOGIN sa WITH PASSWORD = ‘newpassword’
GO
[/sql]

Following are the error and error states:
error 18456 severity 14 state 1
error 18456 severity 14 state 2
error 18456 severity 14 state 5
error 18456 severity 14 state 6
error 18456 severity 14 state 7
error 18456 severity 14 state 38
error 18456 severity 14 state 8
error 18456 severity 14 state 9
error 18456 severity 14 state 11
error 18456 severity 14 state 12
error 18456 severity 14 state 28
error 18456 severity 14 state 38

Complete log of the error message in ssms:
[xml]
sql server error 18456

Login failed for user ‘username’.

Complete error log would look like this:

===================================

Cannot connect to servername.

===================================

Login failed for user ‘username’. (.Net SqlClient Data Provider)

——————————
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=18456&LinkId=20476

——————————
Server Name: servername
Error Number: 18456
Severity: 14
State: 1
Line Number: 65536

——————————
Program Location:

at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.SqlServer.Management.SqlStudio.Explorer.ObjectExplorerService.ValidateConnection(UIConnectionInfo ci, IServerType server)
at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser()
[/xml]

References: MSDN.

]]>
https://sqlserverlearner.com/2011/12/09/microsoft-sql-server-error-18456/feed/ 0