I need to grant a db_datawriter
before executing SqlBulkCopy
and remove it after:
try
{
"EXEC [db_mod].[sys].[sp_addrolemember] N'db_datawriter', N'my_user'" // via SqlCommand
bulk.WriteToServer(table);
}
finally
{
"EXEC [db_mod].[sys].[sp_droprolemember] N'db_datawriter', N'my_user'" // via another SqlCommand
}
but I'm getting an error:
User does not have permission to perform this action.
How can I fix that?