Basically the main reason of this error is the unavailability of default user database at the time of connection. It is possible that the database:
• Is in suspect mode.
• No longer exists.
• Is in single user mode and the only available connection is already being used by someone else or by something else.
• Has been detached.
• Has been set to the RESTRICTED_USER state.
• Is offline.
• Is set to emergency status.
• Does not have the login account mapped to a user or the user has been denied access.
• Is part of a database mirror.
To resolve such error you must specify a valid, available database in the connection string. To avoid the error when the user's default database is unavailable, log on as a user who can modify logins. Then, change the user's default database to a database that is currently available for a connection.