SQL Server 2008 Cannot open user default database - error 4064 - sql-server

I have a database application which has been working fine in the past, but since restoring my server a few weeks ago the main user login has stopped working -
I get this error when I try to login from SSMS.
The default database is defined correctly for the user in question, and I can connect to (and query) that database using the sa user. The database is online, set to MULTI_USER, isn't set to emergency status, and isn't part of a database mirror. The user that is being denied access is not a member of a group, and I've confirmed that the default database is set correctly for that user. If I can connect to the database in question using the sa user then clearly there's a problem with my chosen user/login, but I've run out of ideas. Can anyone help?
I'm running SQL Server 2008 on a Windows 2008 Server.

You can get this error in following cases:
database does not exist
database cannot be open (is offline, is restoring, etc)
your login is not mapped to the database
If you are sure that database exists and is online, you user can be orphaned.
This means that the login's sid does not correspond to user's sid, this could be caused by restore.
You can fix tihis by altering your user with login:
alter user MyUser with login = MyLogin

Related

SSIS cannot connect to SSMS using SQL Server Authentication

I'm trying to set up a connection to SSMS from SSIS project I'm working on with SQL Server Authentication.
I set up a cube_user login and gave it permission to my database transactions
Here is how I set up my cube_user:
Login Name, password. I also chose the default DB below to transactions, the appropriate DB.
Then in User Mapping tab, I gave user owner permissions and I checked in the appropriate DB
Having done all that, it seems like it should work. I then started an SSIS project and tried to connect to it like this:
As you can the drop down that is supposed to display databases, is blank. However, If i tried to connect to it using Windows Authentication, I am able to see all DBs....
Is there something wrong I'm doing. Can you not connect to SSMS using SQL Server Authentication?
Please check the following things:
In properties of cube_user - that it has at least guest rights on the RDBMS (SQL Server itself). User rights on specific DB will not give the permission to connect to SQL Server. The properties are in SSMS - Security\Logins - specific Login properties - Server Roles. See example below
On the third screenshot where you specify user name and password - specify those of cube_user, not admin.
The reason why you see list of DBs with Windows Auth - you do it under your account which presumably has DBA user rights on the SQL Server.

Could not obtain information about windows nt group/user sql server error

I migrated my Access Backend to SQL Server using SQL Server Migration Assistant. During the Installation of SQL Server I made sure that my windows account was set up as the sys admin. When I view my login "office/dave" I can see that I have sys admin server role. I have access to every objects in the SQL Backend when I am browsing through SSMS but I could not access the database diagrams.
I did fix this issue by changing the database owner to [sa] from "office/dave" in the database properties and this let me access the database diagram but I do not understand why this fixed the problem.
I was connected as sys admin and database owner. Why is this fix needed?
This might help someone in the future. This error can occur which did for me because I was logged in as Domain User and was not connected to local User. This error can be fixed by changing the database owner to [sa] account.

Cannot create a new database in Sql Server - changed username

I installed Sql Server on a server in a company I used to work for.
I left the company - and rejoined a year later - and now I have a different domain login.
I've logged on to the server again, and in SSMS tried to create a new database - however I get the error:
create database permission denied in database 'master'
I have tried changing permission and adding DBCreator to BuiltInUsers and to SA - and also tried adding my new domain name to the security section - but when I try to add DBCreator to my user name, I get the error:
Cannot alter the server role 'dbcreator' because it does not exist or you do not have permission
Is there any way I can take control of the Sql Server instance again, to allow me to create new databases?
Thanks for any help,
Mark
I faced this problem when I made another SQL user which I login with, and I tried to give this user [dbcreator] grant.
I solved this via
runnig sql server as administrator
switching to my windows authentication.
going to folder Security -> Logins and double click on my new sql login user.
selecting Server roles and give grant to my user.

Cannot add user to SQL Server 2012 database

I am trying to add a user to SQL Server 2012 Express by right clicking the users folder and clicking add.
I am selecting "SQL user with login" and filling out login info but it is giving me this error:
I am running Windows Web Server 2008 R2. I have tried different names in case it was conflicting and no joy. There is already a user in another database that someone else added previously. I tried to add a user to that database and got the same error so I am not sure what they did differently to me.
I tried running SQL Server Management Studio as administrator but when I do that the add user dialog changes and only lets me create windows user, no sql with login option is there.
I have also tried with a query:
CREATE LOGIN loginname
WITH PASSWORD = 'pass'
It says it is completed successfully but no user is created.
Anyone know what I am doing wrong?
You need to create a login to the server, then a user in the database.
Create Login
Create Database User
If you successfully created loginname, at the server level folder in SSMS, double click on the login and you will see options to grant the user permissions to the necessary database as well as assign a server level role. Once the login is configured and you have given permissions to the database, you can look in the User folder of the database and see the user.
Also answered in:
How do I create a new user in SQL Server 2012 that I can use in a connection string?
Does your SQL user you're logging in with have priv to create a user? This is not the same as launching the application with an elevation (right clicking the shortcut, and clicking run as administrator).

Why cannot login to restored SQL Server 2012 database?

As part of the effort for developing a Windows Service, I restored a production database to a test database on the same SQL Server instance, and can access the test database just fine via SSMS. I gave db_owner role to the database to two other users that are unable to login, both getting SQL error
Error: 18456, Severity: 14, State: 38.
Login valid but database unavailable (or login not permissioned)
Here is the basic message which mentions the database in question as the problem.
Login failed for user 'NT AUTHORITY\SYSTEM'. Reason: Failed to open the explicitly specified database 'MedFile_TestDataServer'. [CLIENT: ]
The database is not in "Restoring" status.
First user is NT Authority\System and the second a Windows user. Both credentials are used to run the Windows service that access the database in update mode, the system user from the same server, the Windows user from VS2013 running the service as a command program on my desktop. Both can get at other copies of this same database just by changing the database name so don't think a connection string issue. I have compared every property on the databases that work and do not work and see no differences except the file names and these two logins have less permissions on the databases that they can access.
Almost like this database is being kept unavailable after being restore but I can find no such property set on the database and I can access via SSMS. I've restarted the server containing the database ergo SQL Server as well.
I also tried running the service as a database administrator and get the same error even though that user accesses the db just fine via SSMS.
Is there anything that can make the database "unavailable"?
This is part of software development for a Windows service trying to use a test database. I am using both EF 6.02 and the latest ADO.NET version as well.
Check if your database has "Auto Close" property set to "True". If so, change it to "False".
You can see it from SSMS: right-click on database - Properties - Options.
can you check what is the Default database for those two users?
If you have (accidentally / purposefully) set a default database for the SQL Server Login user, and the user does not ahve permissions to access the database, you'll get this error.

Resources