I have created 2 SQL Server Database Projects in VS 2013 and imported schemas from 2 databases that reside on the same SQL instance. Both databases have SQL Users, let's say [MyUser1] and [MyUser2], that use a single SQL Login, let's say [MyLogin]. The issue is both projects want to create the SQL Login and this causes the error
"SQL71508 The model already has an element that has the same name MyLogin"
DB1 Project
CREATE LOGIN [MyLogin] WITH PASSWORD = N'xyz';
CREATE USER [MyUser1] FOR LOGIN [MyLogin];
DB2 Project
CREATE LOGIN [MyLogin] WITH PASSWORD = N'xyz';
CREATE USER [MyUser2] FOR LOGIN [MyLogin];
I've tried:
Using the following to check if Login already exists, however an error is generated at the "If" indicating, "SQL700001 The statement is not recognized in this context".
If Not Exists (Select name From master.sys.server_principals Where name = 'MyLogin')
Begin
CREATE LOGIN [MyLogin]
WITH PASSWORD = N'xyz';
End
Does anyone have any thoughts on how to correct or work around this issue? Thanks!
Also, my primary reason for creating the DB2 project was due to views in DB1 that are based on tables in DB2. Without the DB2 project referenced in the DB1 project, the SQL to create the views generated errors about not finding the tables in DB2. So, if anyone has any thoughts on how to workaround this issue, that would be helpful too.
Never add the same item twice in SSDT projects. Where the same item exists in more than one project, create a master project for the server.
Leave the users alone, just move the logins to a common project.
Think inheritance when designing SSDT projects. Do not forget to include the IncludeCompositeObjects switch for deployments of each individual database.
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