Fixing “Login failed for user 'sa'. (Microsoft SQL Server, Error 18456)”
Tags: tutorial, sqlserver, authentication, database
Published: 2023-08-06 20:42:30

## Introduction:
Encountering the “Login failed for user ‘sa’. (Microsoft SQL Server, Error 18456)” error can be a frustrating experience for database administrators and developers. This error typically occurs when there’s a problem with the authentication process. In this blog, we will explore some common reasons for this error and solutions to fix it. Let’s dive in!

---


## Solution 1: Verify Username and Password
Double-check the username and password. It’s possible that either the username is misspelled or the password has been changed without updating your connection string.

---


## Solution 2: Check SQL Server authentication mode
Ensure that your SQL Server is configured to allow SQL Server authentication. Without that, it won’t allow the login with login name and password. To change the authentication mode, follow these steps:

1. Connect to SQL Server using a Windows Authentication account with administrative privileges.

2. Open SQL Server Management Studio (SSMS) and right-click on the server instance and select “Properties”.

    ![Open SSMS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1siskemupv47jr09nl3a.png)



3. Navigate to the “Security” tab. Choose “SQL Server and Windows Authentication mode”. Click on “OK” to save the changes.

    ![Security tab](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/91s14jppxsvwoerk947j.png)



4. Right-click on the server instance and select “Restart” to restart the SQL Server service.

    ![Restart](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g79m72k1i0yo2dlcsvv9.png)


---

## Solution 3: Reset ‘sa’ Password
If you suspect that the ‘sa’ account’s password is incorrect, you can reset it. If you have administrative privileges on the SQL Server instance, follow these steps:

1. Log in to SQL Server using Windows Authentication.

2. Expand the “Server instance” and then “Security”. Inside “Security” expand “Logins”. Right click on ‘sa’ and select “Properties”.


    ![Security](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gyg8wo4nrifozmlwzxpk.png)


3. Reset the password.

    ![Reset](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2m3eojeelo61bipsrhiy.png)


---


## Solution 4: Verify SQL Server Services
Sometimes, the error 18456 can occur if the SQL Server services are not running correctly. To check and start the services, do the following:

1. Press “Win + R,” type “services.msc,” and press Enter.

    ![Services](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pumz6kkgl7v62k6j8jt0.png)



2. Look for “SQL Server” in the list of services.

3. Ensure that the status of service is “Running.” If not, right-click on the service and select “Start.”

    ![Check status](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ldv3q8ixqxrtybfwboe.png)


---

## Solution 5: Unlock the ‘sa’ login
If multiple failed login attempts occur, the ‘sa’ login account might get locked out. To unlock the ‘sa’ account, follow these steps:

1. Connect to SQL Server using a Windows Authentication account with administrative privileges.

2. Expand the “Server instance” and then “Security”. Inside “Security” expand “Logins”. Right click on ‘sa’ and select “Properties”.

    ![Properties](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ufnzluf6liinqyrxxz8m.png)



3. In the “Status” tab, check the “Login” option. Check the “Enabled” option, if it’s not checked.

4. Click “OK” to apply the changes.

    ![Click ok](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/92qwohaiba6lyd8im1ap.png)


---


## Conclusion:
The “Login failed for user ‘sa’. (Microsoft SQL Server, Error 18456)” error can stem from various sources, ranging from incorrect credentials to database configuration problems. By systematically following the solutions outlined in this blog post, you can troubleshoot and resolve the issue, ensuring smooth access to your SQL Server instance. Remember that each environment may have unique factors contributing to the error, so patient investigation is key to finding an effective solution.