I was getting this error everytime I tired to build my VSTS Database project. The project had been created as a “database project” and not a “server project”.
Because logins are server level objects, they do not get imported as part of the schema into the database project and hence you see the error.
The method that I used (and liked) to solve the problem was to create a 2nd database project which I setup as a “server project”. This one imported login ids and whole lot of other stuff. I then deleted all the other parts that belonged to the project, leaving behind only the login objects.
Finally, I referenced this database project in my main database project.
Voila! and it worked!
Why do I prefer this (over just having a single server project)? because when you create your deployment script – there are 2 scripts created one thats based on the server project and the other based on your database project. In my case, the server project contains all kinds of crap that I typically never need unless I am standing up a new server, so I can ignore it and work only with the main database project.
very good work, sometimes i hate database projects ;)
ReplyDeleteNice, precise doco. Thanks!
ReplyDeleteI want to use te variable reference for login name. How do we delcare the variables for login name?
ReplyDeleteCREATE USER [$(ReportLogin)] FOR LOGIN [$(ReportLogin)];
Above script i used and defined the variable the sqlcmdvar file. But i am getting the same error
Error 146 SQL03006: User: [$(ReportLogin)] has an unresolved reference to Login [$(ReportLogin)].