I’m trying to connect to a database running on my local machine from my web application. I can connect to other databases that I created but not this one that I restored from another server. I can connect to the database using the MS SQL Server Management Console and see the database contents, tables etc. but when I try to open an SQL connection I get the error:
“Cannot open database “[Database Name]” requested by the login. The login failed. Login failed for user ‘[DOMAIN\USERNAME]'”
I have tried setting the login properties User Mapping to dbo and set database role membership to db_owner. I also tried switching to mixed mode where I created a SQL account which also works in management studio but not in my application. My application code works with other databases so it’s not the connection string, must be a permissions problem but I’m not seeing it. Any ideas?
When bringing over a backup from another server, the login names that exist under
Security\Usersis no longer valid because those logins (even though they are mapped to Windows accounts) are valid only for the server the database was on.In effect, you will have to remove and then re-add the logins.