Skip to content

Commit d139bf6

Browse files
author
Travis Fields
committed
Fixed bug with login exists, and creation
1 parent f7b042a commit d139bf6

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

templates/create/login.sql.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ BEGIN
88
ELSE ALTER LOGIN [<%= @login %>] DISABLE
99

1010
ALTER LOGIN [<%= @login %>] WITH
11-
<% if @type != 'WINDOWS_LOGIN' -%>
11+
<% if @login_type != 'WINDOWS_LOGIN' -%>
1212
CHECK_EXPIRATION = <% if @check_expiration %>ON<% else %>OFF<% end %>,
1313
CHECK_POLICY = <% if @check_policy %>ON<% else %>OFF<% end %>,
1414
<% end -%>
@@ -29,7 +29,7 @@ END
2929
ELSE
3030
BEGIN
3131
CREATE LOGIN [<%= @login %>]
32-
<% if @type != 'WINDOWS_LOGIN' -%>
32+
<% if @login_type !~ /WINDOWS_LOGIN/i -%>
3333
WITH
3434
PASSWORD = '<%= @password %>',
3535
CHECK_EXPIRATION = <% if @check_expiration %>ON<% else %>OFF<% end %>,

templates/query/login_exists.sql.erb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ IF NOT EXISTS(
2929
) THROW 51000, 'ERROR: the login is not in the correct state', 10
3030
/* If it does exist check for each role is in the correct state */
3131
<% @svrroles.each do |role, enable_bit| %>
32-
IF IS_SRVROLEMEMBER('<%= role %>','<%= @login %>') != <%= enable_bit %> THROW 51000, 'ERROR: a role is not correct for <%= role %>', 10
32+
IF (SELECT COUNT(me.role_principal_id) from sys.server_role_members me
33+
JOIN sys.server_principals rol ON me.role_principal_id = rol.principal_id
34+
JOIN sys.server_principals pri ON me.member_principal_id = pri.principal_id
35+
WHERE rol.type_desc = 'SERVER_ROLE'
36+
AND rol.name = '<%= role %>'
37+
AND pri.name = '<%= @login %>') != <%= enable_bit %>
38+
THROW 51000, 'ERROR: a role is not correct for <%= role %>', 10
3339
<% end %>
3440

3541
<% end %>

0 commit comments

Comments
 (0)