-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddDbUserForHpcService.sql
42 lines (31 loc) · 1.08 KB
/
AddDbUserForHpcService.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
BEGIN
TRY
if not exists (select * from sys.server_principals where name = '$(TargetAccount)')
begin
/* create login [$(TargetAccount)] from windows; */
CREATE LOGIN [$(TargetAccount)] WITH PASSWORD = '$(PassWord)', CHECK_EXPIRATION = OFF;
end
END TRY
BEGIN CATCH
END CATCH
if not exists (select * from sys.database_principals where name = '$(TargetAccount)')
begin
create user [$(TargetAccount)];
if @@error <> 0 return;
end
ALTER USER [$(TargetAccount)] WITH LOGIN = [$(TargetAccount)];
exec sp_addrolemember 'db_datareader', '$(TargetAccount)';
if @@error <> 0 return;
exec sp_addrolemember 'db_datawriter', '$(TargetAccount)';
if @@error <> 0 return;
exec sp_addrolemember 'db_ddladmin', '$(TargetAccount)';
if @@error <> 0 return;
exec sp_addrolemember 'db_owner', '$(TargetAccount)';
if @@error <> 0 return;
-- Enable HPC service to use user-defined FUNCTION
grant exec to [$(TargetAccount)];
if @@error <> 0 return;
-- Enable HPC service to query database extended property DbVersion
grant view definition to [$(TargetAccount)]
if @@error <> 0 return;
GO