?
Solved

Cannot Open User Default Database (error 4064)

Posted on 2007-10-02
3
Medium Priority
?
620 Views
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
0
Comment
Question by:AdibRahman77
3 Comments
 
LVL 7

Accepted Solution

by:
tcicatelli earned 1000 total points
ID: 19998958
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.
-Tom
0
 
LVL 27

Expert Comment

by:ptjcb
ID: 19999080
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.
0
 
LVL 18

Assisted Solution

by:Yveau
Yveau earned 1000 total points
ID: 20000523
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]
GO

CREATE LOGIN MyDomain\MyUser
FROM WINDOWS
WITH DEFAULT_DATABASE = MyDatabase
GO

USE [MyDatabase]
GO

CREATE USER MyDomain\MyUser
FOR LOGIN MyDomain\MyUser
GO

Hope this helps ...


0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

864 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