Cannot Open User Default Database (error 4064)

Posted on 2007-10-02
Last Modified: 2008-01-09
I am getting the following error from while connecting  to a database Server (Sql Server 2005)

"Cannot Open User Default Database (error 4064)."

Thanks in advance
Question by:AdibRahman77
    LVL 7

    Accepted Solution

    According to a Google search:

    You can resolve this by specifying another database you want to connect to; master, for example. Then you can reset the login's default database. With sqlcmd, you can do the following:

    sqlcmd -d master -U sa -P mypassword

    and then:

    alter login sa with default_database = master

    Hope this helps.
    LVL 27

    Expert Comment

    Avoid using master as the default database. It is a security risk, and users should not have access to the master database.

    The default database should be available, and the user should have access to that database.

    You can check this by opening Management Studio > security > logins. Find the user and right-click to check the properties. The default database is listed at the bottom of the General page.

    If the user does not have permissions to the default database, you will see this error.
    LVL 18

    Assisted Solution

    When you did set the default database for the login, did you also create a user in the database ?
    That needs to be done as well, and is NOT done automatically !!!

    so, the complete script would be:
    USE [master]

    CREATE LOGIN MyDomain\MyUser

    USE [MyDatabase]

    CREATE USER MyDomain\MyUser
    FOR LOGIN MyDomain\MyUser

    Hope this helps ...


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
    If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video discusses moving either the default database or any database to a new volume.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now