I have a Visual Studio database project, every time I publish it to SQL Server, it removes the NT AUTHORITY\NETWORK SERVICE Login user.
After every publish I then have to go back into SQL Server Management Studio and add the user again via the User Mapping tab.
Does anyone know why this is and how I can stop it from doing this?
I currently have this in the dbo -> Security folder, but we have other project that also just have this and work fine with the NT AUTHORITY\NETWORK SERVICE.
Managing settings like this can be difficult to figure out, set up, and get consistently correct, as there are a lot of situations and project settings to deal with. Start with the following, then poke around, do some experiments--it can be done.
When publishing a database from VS, you should get this screen. Clicking on Advanced...
Will get you this dialog (note that I am showing the SECOND tab)
Scroll down and select the "Do Not Drop Users" checkbox.
You would need to do this every time you publish the database--but fortunately you can save a publish "Profile"--back on the first screen, via the "Save Profile" buttons. We add these profiles in their own "Publish" folder in the project (tagged with Build Action = None) for ease of access and use.
The (very) irritating thing is, there are a LOT of settings and checkboxes buried in here, and a number of them impact database security and permissions settings. I'm reasonably certain this is the only one you'll need to deal with, but there are a lot of other settings and variations to consider. Whatever you hit, odds are there's a setting in here that, once you figure it out, can address it. Good luck!