When I try to install a new database, I'm getting this error from SQL Server 2008.

The server principal "<mydbuser>" is not able to access the database "<mydatabase>" under the current security context.

I looked it up and it says it has something to do with orphaned users when doing a restore. This connection has nothing to do with a restore, it's a brand new database, user and connection, so why am I getting this problem?

Also the process I'm using to create the database and user/login, is the same for all of my databases, so why does this occur sometimes?

Any ideas?


EDIT: per request here's some code that fails, but understand that this works with every other application I've built. Also this is built into an ASP.NET MVC application.


if (!Roles.RoleExists(role.Name))
    Roles.CreateRole(role.Name);  <-- this fails

Oh, another thing that doesn't make sense is that the database in the error message is not the database I'm trying to install to. It is one of the databases in this SQL Server instance (along with a bunch of others) but it's completely different. I can't figure out where it's getting this.

Example: the database I'm trying to install to is 'Rapper' and the database shown in the error message is 'GPS'. Why?

  • 2
    Maybe you could show the code you're using to "install a new database"? Jul 11, 2012 at 17:37

1 Answer 1


I can't create any comment yet. I don't have the required reputation. So I will post an answer!!!

You can view orphanage users in a database using:

exec sp_change_users_login 'report'

And it also might be because the default database of you login try:

exec sp_helplogins 'Login1'

You can change the default db with:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.