Login to Microsoft SQL Server Error: 18456 - sql-server

I am getting this error while trying to connect to the SQL Server.
Microsoft SQL Server Error: 18456
Can anybody tell me what the error code means?

If you're trying to connect using "SQL Server Authentication" then you may want to modify your server authentication:
Within the Microsoft SQL Server Management Studio in the object explorer:
Right click on the server and click Properties
Go to the Security page
Under Server authentication choose the SQL Server and Windows Authentication mode radio button
Click OK
Restart SQL Services

Check out this MSDN blog article from the data platform team.
You really need to look at the state part of the error message to find the root cause of the issue.
2, 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, 12 = Valid login but server access failure
13 = SQL Server service paused
18 = Change password required
Afterwards, Google how to fix the issue.

Before opening, right-click and choose 'Run as Administrator'. This solved the problem for me.

I have faced this issue.
Please look at the attached image,
Step 1: Go to server property
Step 2: Go to Security
Step 3: Change server authentication as SQL server and WindowsAuthenication mode
and restart your Sql server.

first see the details of the error
if "state" is "1"
Ensure the database is set for both SQL and Windows authentication under SQL server / Properties / Security.
for other state see the above answers ....

Just an update, here is the solution if anyone else has there error with a properly configured login:
If you're trying to connect using "SQL Server Authentication" then you may want to modify your server authentication:
Within the Microsoft SQL Server Management Studio in the object explorer:
Right click on the server and click Properties
Go to the Security page
Under Server authentication choose the SQL Server and Windows Authentication mode radio button
Click OK
Restart SQL Services

Check whether mixed mode authentication is enabled in you server->properties
Then create a login in the server->security
create an user for that login in your database
Then restart your server by right clicking the instance and select restart

If you change a login user credential or add new login user then after you need to log in then you will have to restart the SQL Server Service. for that
GO to--> Services
Then go to SQL Server(MSSQLSERVER) and stop and start again
Now try to log in, I hope You can.
Thanks

Just happened to me, and turned out to be different than all other cases listed here.
I happen to have two virtual servers hosted in the same cluster, each with it own IP address. The host configured one of the servers to be the SQL Server, and the other to be the Web server. However, SQL Server is installed and running on both. The host forgot to mention which of the servers is the SQL and which is the Web, so I just assumed the first is Web, second is SQL.
When I connected to the (what I thought is) SQL Server and tried to connect via SSMS, choosing Windows Authentication, I got the error mentioned in this question. After pulling lots of hairs, I went over all the setting, including SQL Server Network Configuration, Protocols for MSSQLSERVER:
Double clicking the TCP/IP gave me this:
The IP address was of the other virtual server! This finally made me realize I simply confused between the servers, and all worked well on the second server.

Right Click the User, go to properties, change the default database to master
This is the screen print of the image which shows what you have to check if you have the error 19456. Sometimes it default to a database which the user doesn't have permission

18456 Error State List
ERROR STATE ERROR DESCRIPTION
State 2 and State 5 Invalid userid
State 6 Attempt to use a Windows login name with SQL Authentication
State 7 Login disabled and password mismatch
State 8 Password mismatch
State 9 Invalid password
State 11 and State 12 Valid login but server access failure
State 13 SQL Server service paused
State 18 Change password required
Potential causes
Below is a list of reasons and some brief explanation what to do:
SQL Authentication not enabled: If you use SQL Login for the first time on SQL Server instance than very often error 18456 occurs because server might be set in Windows Authentication mode (only).
How to fix? Check this SQL Server and Windows Authentication Mode page.
Invalid userID: SQL Server is not able to find the specified UserID on the server you are trying to get. The most common cause is that this userID hasn’t been granted access on the server but this could be also a simple typo or you accidentally are trying to connect to different server (Typical if you use more than one server)
Invalid password: Wrong password or just a typo. Remember that this username can have different passwords on different servers.
less common errors: The userID might be disabled on the server. Windows login was provided for SQL Authentication (change to Windows Authentication. If you use SSMS you might have to run as different user to use this option). Password might have expired and probably several other reasons…. If you know of any other ones let me know.
18456 state 1 explanations: Usually Microsoft SQL Server will give you error state 1 which actually does not mean anything apart from that you have 18456 error. State 1 is used to hide actual state in order to protect the system, which to me makes sense. Below is a list with all different states and for more information about retrieving accurate states visit Understanding "login failed" (Error 18456) error messages in SQL Server 2005
Hope that helps

Also you can just login with windows authentication and run the following query to enable it:
ALTER LOGIN sa ENABLE ;
GO
ALTER LOGIN sa WITH PASSWORD = '<enterStrongPasswordHere>' ;
GO
Source: https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/change-server-authentication-mode

First go to start bar then search local services
Then click on "view local services"
Then it will open service window then go to SQL Server(MSSQLSERVER) right click on it and click on stop and then again right click on it and click start. Now you can able to login and put your user name as 'sa' and password is your won password.

Please check to see if you are connected to the network if this is a domain member PC. Also, make sure you are not on a dual home PC as your routes may be incorrect due to network metrics. I had this issue when I could not connect to the domain the SQL windows authentication switched to the local PC account but registered it as a SQL authentication. Once I disabled my wireless adapter and rebooted, the Windows integration switched back to the domain account and authenticated fine. I had already set up Mixed mode as you had already done as well so the previous posts do not apply.

For me, it was wrong login and password.

I believe this can happen if you are trying to log in with a user that is defined in Active Directory, but attempt using "SQL Server Authentication" in the login screen. I do not know how to specify a different user with NTLM/Windows Authentication: When I click the Windows Authentication dropdown, the username and password is blanked out, and I can only log in as myself.

In my case multiple wrong attempts locked the account.To do that I had tried running the below query and it worked:
ALTER LOGIN WITH PASSWORD= UNLOCK
And make sure to set the option "Enforce Password Security" option for specific user to be unchecked by right click on Sql Server -> Properties.

SQL Server connection troubleshoot
In case you are not able to connect with SQL Authentication and you've tried the other solutions.
You may try the following:
Check connectivity
Disable Firewall.
Run PortQry on 1434 and check the answer.
Check the state
Try to connect with SSMS or sqlcmd and check the message.
State 1 is rarely documented but it just mean you don't have the right to know the true state.
Look at the log file in the directory of SQL server to know what is the state.
The State 5
What ? my login doesn't exist ? it's right there, I can see it in SSMS. How can it be ?
The most likely explanation is the most likely to be the right one.
The state of the login
Destroy, recreate it, enable it.
reset the password.
Or...
"You don't look at the right place" or "what you see is not what you think".
The Local DB and SQLEXPRESS conflict
If you connect with SSMS with Windows authentication, and your instance is named SQLEXPRESS, you are probably looking at the LocalDb and not the right server. So you just created your login on LocalDb.
When you connect through SQL Server authentication with SSMS, it will try to connect to SQLEXPRESS real server where your beloved login doesn't exist yet.
Additional note: Check in the connection parameters tab if you've not forgotten some strange connection string there.

Another worked solution for me.
serever->security->logins->new logins->General->create your user name as login name,Click sql server authentication add passwords
uncheck the password verification three checkboxes .
This will work.
Remeber to change the server properties ->Security from Server authentication to SQL Server and Windows Authentication mode

you can do in linux for mssql
change password for sa account
sudo /opt/mssql/bin/mssql-conf setup
The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746388 Jump Jump
and found in /usr/share/doc/mssql-server/LICENSE.TXT.
Do you accept the license terms? [Yes/No]:yes
Setting up Microsoft SQL Server
Enter the new SQL Server system administrator password: --Enter strong password
Confirm the new SQL Server system administrator password: --Enter strong password
starting Microsoft SQL Server...
Enabling Microsoft SQL Server to run at boot...
Setup completed successfully.

I got this error after creating a new sysadmin user under my SQL instance.
My admin user was created under a specific domain
MyOrganization/useradmin
Using useradmin on a disconnected environment allows you to create other users using SQL Server authentication, but as soon as you try to login you get
Microsoft SQL Server Error: 18456
To fix the problem, try to connect again to your Organization network and create the user while you are connected and then you can get disconnected and will work.

I have faced the same issue. In case you see it, run this query:
DBCC FREEPROCCACHE
DBCC DROPCLEANBUFFERS
then it shows a 18456 error code.
Do one thing again run same query after reconnecting SQL server. It will work fine.

Click on "Options" and under "Connection Properties" specify the catalog/database name next to "Connect to database:". I got the error because this was set to <default> and I needed to specify the dbname.

Microsoft SQL Server, Error: 18456
I was getting an issue because I was entering the wrong password.
Microsoft SQL Server, Error code: 18456 - This indicates that the password is incorrect.
Reference: https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/mssqlserver-18456-database-engine-error?view=sql-server-ver16

it happen with me when I have restored my computer
enable windows and sql authentication
reboot your PC
in vs code in my case still in error because i forget install pyodbc :D

Related

Can't connect to SQL locally with SQL Server authentication

I configure a SQL Server instance and I have a problem with de SQL Server authentication when I try to connect locally (instance server).
When I connect to SQL remotely, the SQL Server authentication works fine, but when I try to connect locally, the server returns me the SQL Error 18456.
I don't know what's happened... I can connect remotely but not locally
If your instance is called SQLEXPRESS, then you need to use .\SQLEXPRESS or (local)\SQLEXPRESS or yourMachineName\SQLEXPRESS as your server name - if you have a named instance, you need to specify that name of the instance in your server name.
There isn't enough information in this question to give an answer. The only certainty is that a local or remote connection doesn't really affect how authentication is performed.
Short Answer
Make sure you are connecting to the correct server. If you are, check SQL Server's log for the failed login message. The state number of the message explains the failure reason. In the SSMS Object Explorer, go to Management > SQL Server Logs > Current.
Long Answer
The fact that the error is 18456 means that you can connect to a server but the credentials are rejected.
One reason for this may be that you are connecting to the wrong server: when connecting to an instance, you must always provide the instance name, eg: .\INSTANCE or MACHINE\INSTANCE. If you click on the Technical Details button in the SSMS error dialog, you'll see what server\instance you tried to connect to. For security reasons, no other information is disclosed in this message.
BTW, clicking on the help button of the dialog box will open a help page with a quick explanation of what might have happened.
To diagnose a real authentication problem, you need to find the full error message. The full message, including a state number that explains the reason, is stored in the server's Log. In SSMS, you'll find the log in Management > SQL Server Logs > Current.
In general, checking SQL Server's log should be the first action when an error is encountered that isn't directly related to a SQL statement.
The meaning of the various states is discussed in this similar SO question, described in this MSDN blog post and this detailed article by Aaron Bertrand.
A quick list of state numbers, copied from the SO question:
2, 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, 12 = Valid login but server access failure
13 = SQL Server service paused
18 = Change password required

No process is on the other end of the pipe (SQL Server 2012)

I've got this error:
A connection was successfully established with the server, but then an error occurred
during the login process. (provider: Shared Memory Provider, error: 0 - No process is
on the other end of the pipe.)
(Microsoft SQL Server, Error: 233)
I know, there are similar questions on this site, and the answer is, to enable TCP/IP and pipes.
But I enabled both, and still doesn't work:
I am using Microsoft SQL Server 2012 and the user has full permissions.
The server was set to Windows Authentication only by default. There isn't any notification, that the origin of the errors is that, so it's hard to figure it out. The SQL Management studio does not warn you, even if you create a user with SQL Authentication only.
So the answer is: Switch from Windows to SQL Authentication:
Right click on the server name and select properties;
Select security tab;
Enable the SQL Server and Windows Authentication mode;
Restart the SQL Server service.
You can now connect with your login/password.
Here are the directions by Microsoft: https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/change-server-authentication-mode?view=sql-server-ver15
To solve this, connect to SQL Management Studio using Windows Authentication, then right-click on server node Properties->Security and enable SQL Server and Windows Authentication mode. If you're using 'sa' make sure the account is enabled. To do this open 'sa' under Logins and view Status.
If this didn't work, you may need to reinstall SQL Server
Also you can try to go to services and restart your Sql server instance
So, I had this recently also, for integrated security, It turns out that my issue was actually fairly simple to fix but mainly because I had forgotten to add "Trusted_Connection=True" to my connection string.
I know that may seem fairly obvious but it had me going for 20 minutes or so until I realised that I had copied my connection string format from connectionstrings.com and that portion of the connection string was missing.
Simple and I feel a bit daft, but it was the answer for me.
Another reason for this error could be incorrect or non-existent database name.
Forcing the TCP/IP connection (by providing 127.0.0.1 instead of localhost or .) can reveal the real reason for the error. In my case, the database name specified in connection string was incorrect.
So, here is the checklist:
Make sure Named Pipe is enabled in configuration manager (don't forget to restart the server).
Make sure the database you are connecting to exists.
Make sure SQL Server Authentication (or Mixed Mode) is enabled.
Please check this also Also check in configuration TCP/IP,Names PipeLine and shared memory enabled
If you are trying to login with SQL credentials, you can also try changing the LoginMode for SQL Server in the registry to allow both SQL Server and Windows Authentication.
Open regedit
Go to the SQL instance key (may vary depending on your instance name):
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQLServer\
Set LoginMode to 2
Restart SQL service and SQL Server Management Studio and try again.
I face this issue for the second time and all previous answers failed, fortunately the following request do the job:
Alter login [user] with CHECK_POLICY = OFF
go
Alter login [user] with CHECK_POLICY = ON
go
For me the password expired for my login user, and i got the same exception.
Then i login with Windows Authentication mode and change the password for the associated user, and it solved my problem.
Yup, this error might as well be "something failed, good luck figuring out what" - In my case it was a wrong username. SQL Server 2019 RC1.
Had this error too, the cause was simple, but not obvious: incorrect password. Not sure why I didn't get just "Login failed" from freshly installed SQL 2016 server.
I have the same proplem
"A connection was successfully established with the server, but then an error occurred
during the login process. (provider: Shared Memory Provider, error: 0 - No process is
on the other end of the pipe.)"
My connection is:
server=POS06\SQLEXPRESS; AttachDbFilename=C:...\Datas.mdf;Initial Catalog= Datas; User ID= sa; Pwd=12345; Connect Timeout=10;
But My SQL is POS06\MSQL2014
Change the connection string to
server=POS06\MSQL2014 ; AttachDbFilename=C:...\Datas.mdf;Initial Catalog= Datas; User ID= sa; Pwd=12345; Connect Timeout=10;
it worked.
Always try to log in using those credentials with SQL Management Studio. This might reveal some more details that you don't get at runtime in your code.
I had checked the SQL + Windows authentication, restarted the server but still no luck.
After trying to log in using SQL Management, I got this prompt:
Somehow the password had expired although the login was created just minutes before. Anyway, new password set, connection string updated and all's fine.
This might help others. After writing my db routines at home, all working fine. Brought it to work and got this error as well. Might assert same error, different reason. I mistyped the database name when fixing up my code. Ooohh! More coffee ;) Looking back now, kind of makes sense in my case the login/user was good (an admin account) but with a bad database name, there was nothing on the end of the pipe. Why not say "Database does not exists...? And be clear.
make sure that you have specified user in Security-> Logins, if no - add it and try again.
Follow the other answer, and if it's still not working, restart your computer to effectively restart the SQL Server service on Windows.
In my case the database was restored and it already had the user used for the connection. I had to drop the user in the database and recreate the user-mapping for the login.
Drop the user
DROP USER [MyUser]
It might fail if the user owns any schemas. Those has to assigned to dbo before dropping the user. Get the schemas owned by the user using first query below and then alter the owner of those schemas using second query (HangFire is the schema obtained from previous query).
select * from information_schema.schemata where schema_owner = 'MyUser'
ALTER AUTHORIZATION ON SCHEMA::[HangFire] TO [dbo]
Update user mapping for the user. In management studio go to Security-> Login -> Open the user -> Go to user mapping tab -> Enable the database and grant appropriate role.
In my case: Assign a sysadmin role to the user.
Login as windows authenticated user
Go to: Security->Login->Right click user->Assign server role as sysadmin
In my case, login works fine remotely, via VPN. But connecting from the server where sql server was installed, it failed.
Turns out, the instance name is not the default eg. SQLEXPRESS. Hence, it needs to be explictly specified when connecting.
Server name: .<instance_name>
eg. ".\I01"
I don't have to do this if I'm connecting remotely, just <server_hostname>,<port_number>

Error connecting to SQL Server using SQL Server Management Studio

I've been trying to connect to SQL Server using SQL Server Management Studio to no avail.
This is what the error says:
Cannot connect to .\HAMED.
ADDITIONAL INFORMATION:
Login failed for user 'HAMED'. (Microsoft SQL Server, Error: 18456)
I have an instance of SQL Server by the name of Hamed which is run in Network Sevice mode. I'm using Windows 7.
I'm guessing you didn't grant yourself SQL admin during the install, but are you sure the DB instance is "HAMED"? That sounds like the machine name. Try connecting to .\sqlexpress
Do you remember the SA password? If so, you can add yourself by logging in with that account. Otherwise, you'll have to jump through some hoops and loops to get yourself added.
If you forgot to add yourself to the SQL admin group, read this article:
http://blogs.ameriteach.com/chris-randall/2009/12/11/sql-server-2008-forgot-to-add-an-administrator-account.html
It looks like you're trying to use "SQL Server Authentication" in the login dialog in SSMS, but the user that you're trying to use is a Windows user/administrator? If so, the fix should be as simple as choosing "Windows Authentication" in the drop-down.
UPDATE: looks like I jumped the gun - this sql server forum thread lists lots of possible issues, including permissions issues, orphan users, etc.
sa... the answer was sa.
I had set the administrative password but didn't know the username to go with it. Very nube, I know, you can hit me with it later.
When I installed SQL it asked me to set administrative password - right now SSMS can login.
Under users I see 1\cory (1 is my machine name - I'm trying a numbering scheme). But if I type that in it fails with the error. SQL says "no, that's an NT login, I can't use those".
Under the users list SQL does in fact show the user as Windows authentication but as I said - for some reason I can't connect using Windows authentication. The connection times out.
I'll just add a direct user name here.
All this is to do the MSVA courses for SQL certification. First exam: get sql SSMS to work.

Unable to login to SQL Server + SQL Server Authentication + Error: 18456

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.
You need to enable SQL Server Authentication:
In the Object Explorer, right click on the server and click on "Properties"
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.
Restart the SQLEXPRESS service.
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].
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"
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
After enabling "SQL Server and Windows Authentication mode"(check above answers on how to), navigate to the following.
Computer Mangement(in Start Menu)
Services And Applications
SQL Server Configuration Manager
SQL Server Network Configuration
Protocols for MSSQLSERVER
Right click on TCP/IP and Enable it.
Finally restart the SQL Server.
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
The correct solution to the problem is to make sure SQL server authentication is turned on for your SQL Server.
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.
try using this connection string
Server=ServerName;Database=DbName;Trusted_Connection=SSPI;MultipleActiveResultSets=true;TrustServerCertificate=true

Can't connect to SQL Server Express anymore

I think I made a mistake and I lost my connection to my SQL Server Express.
In SQL Server Management Studio under security I disabled the login option.
Now when I try to connect to the Server I get the message :
"Cannot connect to
HP16969\SQLEXPRESS". Additional
informations : Login failed for user
'HP16969\Bernard (Microsoft SQL
Server, error : 18456)
Is there a way I can correct my earlier mistake ?
Thanks
I really have tried everything but can't connect anymore to SQLEXPRESS. Just because I change The login status to Disabled there seems to be no way for me to reconnect. That is silly!!
I followed the instructions including -m; in the parameter list without any success.
The last option I would like to use is to reinstall Server EXPRESS .After reading many articles on the net I am scared to run into problems...
You need to connect using a login that has access and grant yourself again access back.
If you don't have any login that has access, then you need to restart the server in administrative mode and use a local administrator account to enable back the account 'HP16969\Bernard'. See Troubleshooting: Connecting to SQL Server When System Administrators Are Locked Out.

Resources