Attaching databases results in error "The server principal is not able to access the database" -


i have 2 databases want attach them sql server express.

when try user account, recieve login failed error.

this code sets owner of databases current user

use [databasename]  create user[domainname\\username] login [domainname\\username]  exec sp_addrolemember 'db_owner','domainname\\username' 

this works first database second 1 receive error:

the server principal not able access database

how can done programmatically?

you should change database owner

exec sp_changedbowner 'yourlogin',null 

and

alter database [your_db] set trustworthy on 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -