Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to log in to server in SQL Server 2008 R2 Management Studio

I have a SQL Server 2008 R2 instance and can log in using the sa user. But I want to define another user (administrator) to log in with SQL Server Management Studio, so I did the following:

  • Logged in to the server in Management Studio as sa.
  • Right clicked on the database name.
  • Clicked on properties.
  • Then under permission, I select the required username (administrator).
  • And I grant him all the permission.

But when I tried to log in using administrator, I got the following error:

Login failed for user “administator” Error 18456.

Can anyone advise what might be the problem?

like image 870
John John Avatar asked Dec 19 '22 14:12

John John


2 Answers

If the server encounters an error that prevents a login from succeeding, the client will display the following error mesage.

Msg 18456, Level 14, State 1, Server <server name>, Line 1
Login failed for user '<user name>'
  • This usually means that your connection request was successfully received by the server name you specified but the server is not able to grant you access for a number of reasons and throws error: 18456.
  • This eventID sometimes provides also state 1 which actually isn’t that useful as due to security reasons any error is converted to state 1 unless you can check logging on the server.
  • Microsoft does not provide very useful message boxes so below are some explanations why you get the error.

enter image description here

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….

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

SQL Authentication not enabled: If you use SQL Login for the first time on SQL Server instance than very often error 18456 occurs because Windows Authentication (only) is set in Server properties (security section).

To Access Server Properties, - Open SQL Server Management Studio, go to Object Explorer pane (use view if you can’t see it). - Use the connect button to connect to database engine for your server. Once connected you will see it in object explorer. - Right click server and click properties. Server Properties window will appear.

enter image description here

See below screenshot that might be causing SQL login to fail

enter image description here

You should set Server Authentication to SQL Server Windows Authentication

enter image description here

To resolve this error follow the steps below on computer with SQL Server 2005.

  • Create new user with Administrator privilege with same username and password as of SQL Server 2008 in operating system.
  • On SQL Server database create new user by expanding DatabaseNode >> Security >> Login >> - Create New User and add this new user with Windows Authentication radio button selected. - This user can be only added by selected Windows Authentication it is Operating system’s User Login.
  • Once above two steps are completed when connected from SQL Server 2008 to SQL Server 2005 using Windows Authentication it will connect successfully.

How to fix? Check this link video SQL Server and Windows Authentication Mode page.

Source

like image 154
Amarnath Balasubramanian Avatar answered Dec 28 '22 11:12

Amarnath Balasubramanian


You need to add a server login:

  1. Connect to your SQL Server with SSMS as sa.
  2. Drill into the server's Security folder in SSMS's Object Explorer pane.
  3. Right-click on the server's Security > Logins folder that appears in Object Explorer.
  4. Click on New Login... in the context menu that appears.
  5. Provide details of the new login in the Login - New dialog that opens - particularly its General, Server Roles, and User Mappings pages (along the left). (See the screenshots of each page with sample input at the bottom of the answer.)

You may need to add a database user depending on your needs, but a server login (like your sa login) is necessary to connect to the SQL Server instance using Windows or SQL Server authentication. Mapping the new login to a database user (in the Login - New dialog's User Mappings page) will create a new user in the mapped database if you specify a username that does not already exist; alternatively you can map the new login to an existing database user.

Another SO question speaks to the differences between server logins and database users.

Login - New (General page)

SQL Server authentication

Login - New (General, SQL auth)

or

Windows authentication

Login - New (General, Win auth)

Login - New (Server Roles page)

Login - New (Server Roles)

Login - New (User Mappings page)

SQL Server authentication

Login - New (User Mappings, SQL auth)

or

Windows authentication

Login - New (User Mappings, Win auth)

like image 31
J0e3gan Avatar answered Dec 28 '22 10:12

J0e3gan