I'm trying to create a user with a login for a SSDT database project. The login already exists on the target server. With the following SQL:
CREATE USER [MyLogin]
FOR LOGIN [MyLogin]
WITH DEFAULT_SCHEMA = dbo
GO
I get the error:
Error 1 SQL71501: User: [MyLogin] has an unresolved reference to Login [MyLogin].
I've found two solutions, but neither work with 2013:
1) Create a server project to reference the login. This isn't an option in the current version of SSDT / VS2013
2) Disable schema checking. The option is missing in 2013 (I believe it was Options -> Database Tools -> Schema Compare)
You can actually create the Server Level Login within the SQL Server Database Project using the standard T-SQL Syntax:
CREATE LOGIN [Login_Name] WITH PASSWORD = '<Password>';
Note: You can also right-click the database project and choose 'Add New Item' and navigate to SQL Server > Security (within the templates dialog) and select 'Login (SQL Server)'.
This resolves the SQL71501 Error and (assuming you are using SQLPackage.exe for deployment) will allow SQLPackage.exe the ability to compare the security object with the target Database before deployment and publishing occurs.
Hope that helps :)
If you are guaranteed to have the login on the server, your best bet is to tweak your master dacpac file. There are some instructions on how to do this here: http://sqlproj.com/index.php/2013/02/how-to-add-objects-to-master-dacpac
Alternatively, you could remove references to logins from the SSDT portion and handle it in post-deploy scripts. If you have any sort of environment where different permissions need to be applied in different server (Development, QA, Production), that might be the better option. I've blogged about this here: http://schottsql.blogspot.com/2013/05/ssdt-setting-different-permissions-per.html
Hopefully one of those will help. I've actually used the first option to work around an issue with needing to use EXECUTE AS, which requires that the user is in the project. It was a little tricky to get the exact XML, but I worked around it by creating an empty project with just that login, building it, and copying the XML from the dacpac into the master dacpac.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With