Created
August 18, 2020 13:26
-
-
Save MarioBinder/8be6f39f07bb82845a772e8af7464a07 to your computer and use it in GitHub Desktop.
grant access to database from entity framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var sql = "USE <DBNAME>;" + | |
| "create user [domain\\user] from login [domain\\user];" + | |
| "ALTER ROLE db_datareader ADD MEMBER [domain\\user] ;"; | |
| try | |
| { | |
| using (var ctx = new MyContext()) | |
| { | |
| Info($"Start Grant Acess to xx: {DateTime.Now}"); | |
| ctx.Database.ExecuteSqlCommand(sql); | |
| Info($"End Grant Acess to xx: {DateTime.Now}"); | |
| } | |
| } | |
| catch (Exception exc) | |
| { | |
| Error(exc); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment