When I want to connect to SQL Server 2008, I get this message:
Cannot connect to server.
Additional Information: Cannot open user default database. Login failed. Login fail for user 'sa'. (Microsoft SQL Server. Error:4064)
How do I resolve this error?
This error (Microsoft SQL Server.Error:4064) occurs when the database which is dropped is default for some database user.
When the user tries to login and their default database is dropped the error shows up.
Cannot open user default database. Login failed. Login failed for user
‘UserName’. (Microsoft SQL Server, Error: 4064)
The way to resolve this is given here, summarized below.
The solution to log on is:
From the Connect to Server dialog, click Options
Change value of Connect to database: to any valid database on the server
The permanent solution to fix the server is to run SQL like:
ALTER LOGIN [test] WITH DEFAULT_DATABASE = master
GO
In my case this was due to a user being a member of multiple groups, each group having its own login. All groups' logins need to have their default database set to a database accessible to the user.
Other possible problems are listed at https://support.microsoft.com/en-us/kb/307864.
You can set each login with an invalid default database to have a default database of master (accessible to all logins):
alter login [loginname] with DEFAULT_DATABASE = master
The user default database is unavailable at the time of connection so that this error message will popup .SO check which server you tagged to that particular user to access whether it is online or offline mode.
Related
I made the following settings on my SQL Server 2012 as suggested in many tutorials:
I set the server authentication to "SQL Server and Windows Authentication mode"
I set a strong password with enforced password policy with default database "master" to SA user
I granted the SA user permission to connect to database engine and
enabled his login.
Yet when I try to login to the "localhost"
through the SQL Server Authentication.
it fails with:
Cannot connect to (local).
------------------------------
Login failed for user 'sa'. (Microsoft SQL Server, Error: 18456)
Only possible way how can I login is still the Window authentication.
My instance is named MSSQLSERVER. localhost\MSSQLSERVER is inaccessible.
There could be multiple reasons. Please check your error log and find the state of error. Depending upon the state, error could be -
State Description
1 Error information is not available. This state usually means you do not have permission to receive the error details. Contact your SQL Server administrator for more information.
2 User ID is not valid.
5 User ID is not valid.
6 An attempt was made to use a Windows login name with SQL Server Authentication.
7 Login is disabled, and the password is incorrect.
8 The password is incorrect.
9 Password is not valid.
11 Login is valid, but server access failed. One possible cause of this error is when the Windows user has access to SQL Server as a member of the local administrators group, but Windows is not providing administrator credentials. To connect, start the connecting program using the Run as administrator option, and then add the Windows user to SQL Server as a specific login.
12 Login is valid login, but server access failed.
18 Password must be changed.
For detailed information - MSDN
I've created new user in SQL Server Management Studio (SQL Server 2008 Express) in security tab.
Specified the login name, SQL Server authentication, entered a password, assigned server role sysadmin, mapped to my database and there specify it as db_owner. Also in database security is specified in tab Schemas owned by this user is db_owner.
I've checked a lot of tutorials but all of them do the same as me but when I try to login to SQL server (even manually) error message is thrown:
Login failed for 'MyUser' (Microsoft SQL Server, Error: 18456)
Any idea what's wrong?
Thanks a lot.
Peter
Failed to login SQL Server after installing SQL Server and creating new login user for SQL Server? You can check error description in Error Log file at first. Look for entry and then confirm what "State" means in entry.
After making sure which lead to this SQL Server login error, take appropriate measures. Generally, you would need to do according to different situations.
You would need to change authentication mode to Mix Authentication or SQL Server Authentication mode.
You would have to enable SQL login user if the login is disabled.
Reset SQL Server user password if the login user password is incorrect.
Configure Windows Firewall to allow SQL Server access if the login is valid but server access is failed.
More details about fixing failed login error for user, you can refer to this article.
http://www.isunshare.com/sql-server/fix-sql-server-failed-login-error.html
I came across the same problem and solved mine by changing the Server to Mixed Authentication Mode. In my case, I was trying to log in with a SQL server login, but the server was only set up to accept Windows Authentication.
See this link for how to change it:
http://support.microsoft.com/kb/555332
I realise this question is old, but I hope the answer helps someone.
Thanks
Yesterday my database was connected perfectly.
We have installed Windows Server 2008 R2 on our server and the I have added the user to the client PC name SMTECH5 with user jangid
Now my database is not connecting using windows authentication.
only the master database is connecting.
Here's the the error:
Cannot connect to SMTECH5\COLLEGEERP.
Cannot open user default database. Login failed.
Login failed for user 'SMTECH\jangid'. (Microsoft SQL Server, Error: 4064)
If you go to enterprise manager as a different user, go to the security, logins node and select the user - then change the default database to master.
That should sort it.
The reason is because the default database has been removed (look comment on the question).
You have to Open Sql Server Management Studio, connect to the database, then open Security -> Logins-> right click on the account jangid -> Properties: on the bottom of the window you have to change the default database to the available one, or master.
Try this in SQL Server Management Studio.
1: Open 'Connect to Server' popup
2: Select 'Options >>'
3: Change the value in the dropdown 'Connect to database' from <default> to master.
I have just restored a database backup to my local SQL Server express instance.
In management studio under the server instance node I went to: Security -> Logins -> New login...
Then I filled in a login name, password and chose SQL Server authentication. And at the bottom I selected the newly restored database to be the Default database.
At the User Mapping 'tab' at the left, I mapped the user to the newly restored database and gave it "db_owner" role.
When I try to login the following error is given in the log:
Login failed for user 'username'. Reason: Could not find a login matching the name provided. [CLIENT: ]
How can I make SQL Server find the login matching the name I provided?
Other info:
Named pipes are enabled
TCP/IP is enabled
Remote connections are allowed
Please make sure you have selected "SQL Server Authentication" mode for user you created from
Server > Security > Logins option.
Another possibility, is that you created the SQL Server login using Management Studio, and the option requiring the user to change the password on first login was checked. If you didn't immediately login with Management Studio, and change the password, then the attempt to login from the other machine is not able to pop up a dialog box to change the password and so it fails.
try it by removing user and create again.
This is old but for some one who encounters error for ASP.Net Core 2.2 using EF core and VS Code, I got error
Error Number:18456,State:1,Class:14
Login failed for user 'sa:password=MyPassword'.
I looked logs from SSMS and found error as
Login failed for user 'sa:password=MyPassowrd'. Reason: Could not find a login matching the name provided. [CLIENT: MyIp]
After searching here and there i found that I have to add Persist Security Info=False in connection string, so my connection string became like
"Default":"Persist Security Info=False;User ID=sa;Password=MyPassword;Initial Catalog=MyDb;Server=MyServerIp"
I found this format from Microsoft Docs. After that it worked fine.
persist security info=false is default. I didnot found any reason why my connection string without it was not working. From here
I want to add a user in SQL Server 2008 so I can use SQL Server Authentication instead Windows Authentication for connecting to SQL, and have tried this code to create a user with login:
CREATE login [newLog] with password = 'passnewLognewLog'
I get it done, but when I want to connect to SQL Server using SQL Authentication, I get this message
Cannot connect to "Mydb"
additional information: Login failed for user
'newLog'. (Microsoft SQL Server,
Error: 18456 )
What am I missing here?
After creating the login, you need to add the user to the database. This example is from the sql server documentation for CREATE USER:
CREATE LOGIN AbolrousHazem
WITH PASSWORD = '340$Uuxwp7Mcxo7Khy';
USE AdventureWorks2008R2;
CREATE USER AbolrousHazem FOR LOGIN AbolrousHazem;
GO
Edit
To test, I ran this T-SQL:
create login Foo with password ='f00';
go
use TestDB
create user Foo for Login Foo
go
and opened a connection successfully using this connection string:
"Server=<server>; user id=Foo; password=f00; initial catalog=TestDB"
You need to create a user for the login, e.g.
CREATE USER [newLog] FOR LOGIN [newLog] WITH DEFAULT_SCHEMA=[dbo]
Check that mixed authentication is enabled: https://stackoverflow.com/a/1719476/188926
Try the following. They worked for me when I had this connection issue.
-When you are adding SQL user, make sure 'enforce password policy' is unchecked.
-Make sure that user is mapped to the database with proper permissions.
-on SSMS, right click server and then go to Security tab. Select 'SQL Server and Windows Authentication mode' option.
-restart PC.