Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change sp_addrolemember for ALTER ROLE #384

Open
leedavi opened this issue Sep 24, 2024 · 2 comments
Open

change sp_addrolemember for ALTER ROLE #384

leedavi opened this issue Sep 24, 2024 · 2 comments
Assignees
Milestone

Comments

@leedavi
Copy link

leedavi commented Sep 24, 2024

The sp_addrolemember in SQL will be removed in future. You probably know!

https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-addrolemember-transact-sql?view=sql-server-ver16

I was automating some work and took some of your DB permissions code to do it. The sp_addrolemember gave me some issues with roles already being assigned. I changed it to the ALTER ROLE and the problem was solved.

Change

SqlCommand addRoleMember = new SqlCommand($"sp_addrolemember 'db_owner', '{appPoolName}'", myConn);

to

SqlCommand addRoleMember = new SqlCommand($"ALTER ROLE [db_owner] ADD MEMBER [{appPoolName}] ", myConn);
@david-poindexter
Copy link
Member

Nice @leedavi - thanks! 🎉

@david-poindexter
Copy link
Member

Note to future self:
Here is the line of code being referenced - https://github.com/nvisionative/nvQuickSite/blob/develop/nvQuickSite/Controllers/DatabaseController.cs#L211

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants