Monday, 10 August 2015

SQL: How to fix "Cannot open user default database"

I set my default database to offline, and I could not log in again to the database server saying "Cannot open user default database." To fix this, assign another database to the login.

Open command prompt.
If you are using Windows authentication, type the following:

sqlcmd -E -S <instance name> -d master

ex.
sqlcmd -E -S someservername\someinstance,someport -d master

If you are using SQL Server authentication:
sqlcmd -S <instance name> -d master -U <sqllogin> -P <password>

At the sqlcmd prompt, type the following:

alter login <sql login that you want to fix> with default_database = <an existing DB or master>

ex.
alter login [somedomain\someusername] with default_database = master
go



No comments:

Post a Comment