Skip to content

Instantly share code, notes, and snippets.

@MarioBinder
Created August 18, 2020 13:26
Show Gist options
  • Select an option

  • Save MarioBinder/8be6f39f07bb82845a772e8af7464a07 to your computer and use it in GitHub Desktop.

Select an option

Save MarioBinder/8be6f39f07bb82845a772e8af7464a07 to your computer and use it in GitHub Desktop.
grant access to database from entity framework
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