Thursday, June 18, 2009

TSD03006: User: [username] has an unresolved reference to Login [loginname]

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”.

image

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.

image 

Finally, I referenced this database project in my main database project.

image

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.

3 comments:

  1. very good work, sometimes i hate database projects ;)

    ReplyDelete
  2. Nice, precise doco. Thanks!

    ReplyDelete
  3. I want to use te variable reference for login name. How do we delcare the variables for login name?

    CREATE 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)].

    ReplyDelete

Remember, if you want me to respond to your comment, then you need to use a Google/OpenID account to leave the comment.