I am using sqlpackage.exe to create dynamic databases to run unit tests against. This work locally 100% of the time, but not in TFS. All the unit tests use integrated security for locahost\sqlexpress. TFS will randomly cause sqlpackage.exe to return the following error.
For the unit tests, I am using the pattern described here, but with some modifications to use a dacpac with sqlpackage as oppose to the schema export feature of nhibernate.
sqlpackage error : *** Could not deploy package.
sqlpackage error : Cannot open database "MessagesRepositoryTests" requested by the login. The login failed.
sqlpackage error : Login failed for user 'DOMAIN\TFSService'.
Other (random) errors include another line mentioning that it failed to import the target model.
sqlpackage error : *** Could not deploy package.
sqlpackage error : Failed to import target model MessagesRepositoryTests. Detailed message Cannot open database "MessagesRepositoryTests" requested by the login. The login failed.
sqlpackage error : Login failed for user 'DOMAIN\TFSService'.
sqlpackage error : Cannot open database "MessagesRepositoryTests" requested by the login. The login failed.
sqlpackage error : Login failed for user 'DOMAIN\TFSService'.
"DOMAIN\TFSService" has been granted every server role (sysadmin, public, etc).
Does anyone have a clue why this would show up intermitently throughout all of my tests? Remember, this occurs only from the TFS build automated unit tests.
I am not sure that actual root of the cause, but this issue was resolved when I removed "Delete Test Result" directory from the build process template. It must have something to do with the directory that it is adding the log/data files to being deleted and recreated. I have since change my code to always store the test databases in a folder directly under the C:\ drive.