We created login and password for user to access database in read only mode. But after creating login name when user tries to login, it failed to access the sql server.
Error: Cannot open user default database. Login failed. Login failed for user ‘testlogin’. (Microsoft SQL Server, Error: 4064)
As error suggests, there is some issue with default database. Now let’s check the login properties whether we have assign correct default database for login.
Default database is correct but user mapping was missing.
No user mapping to access default database
To fix this issue, we have to assign db_reader database role permission to login to access default database on sql server.
Now after assigning proper permission to user and user mapping, we retried accessing sql server this time it got logged in.