EDIT I found the solution. Details at this question: How to use a different connection string (but same database) for migrations
I have created a SQL Server login for use by my website:
USE Master
CREATE LOGIN website_live
WITH PASSWORD = N'ItsASecret',
DEFAULT_DATABASE = MyDb,
DEFAULT_LANGUAGE = British,
CHECK_EXPIRATION = OFF,
CHECK_POLICY = OFF
GO
Then I gave it read and write permissions:
USE MyDb
CREATE USER website_live
FOR LOGIN website_live
WITH DEFAULT_SCHEMA = dbo
EXEC sp_addrolemember N'db_datareader', N'website_live'
EXEC sp_addrolemember N'db_datawriter', N'website_live'
And used that login in my connection string
Everything works until I publish from Visual Studio with a database migration that requires a schema change (Edit: by this I mean a change to the structure of the database. I don't mean that I want to change the schema that the website is using).
I don't really want to give the website permanent permissions to alter the database. Can I create another database user that is only used during migrations? Would that be secure? How do I do that and can I keep the convenience of publishing with just a couple of clicks?
NB I'm using Entity Framework migrations. When I publish the website from Visual Studio, the website is automatically opened in a browser then, if there are database migrations to run, these are run using the website's credentials.