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 to ALTER ROLE #384

Closed
leedavi opened this issue Sep 24, 2024 · 2 comments · Fixed by #387
Closed

Change sp_addrolemember to ALTER ROLE #384

leedavi opened this issue Sep 24, 2024 · 2 comments · Fixed by #387
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

@david-poindexter david-poindexter self-assigned this Sep 24, 2024
@david-poindexter david-poindexter added this to the Future: Patch milestone Sep 24, 2024
@david-poindexter david-poindexter modified the milestones: Future: Patch, 2.4.0 Jan 4, 2025
@david-poindexter david-poindexter changed the title change sp_addrolemember for ALTER ROLE Change sp_addrolemember to ALTER ROLE Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants