MCPcopy Create free account
hub / github.com/ActiveState/code / SyncLogins

Function SyncLogins

recipes/Python/578977_Python_SQLSMO_/recipe-578977.py:111–139  ·  view source on GitHub ↗
(conn, db)

Source from the content-addressed store, hash-verified

109 return rows
110
111def SyncLogins(conn, db):
112 s = '''
113 DECLARE @UserName nvarchar(255)
114 DECLARE @SQLCmd nvarchar(511)
115 DECLARE orphanuser_cur cursor for
116 SELECT UserName = name
117 FROM sysusers
118 WHERE issqluser = 1 and (sid is not null and sid <> 0x0) and suser_sname(sid) is null ORDER BY name
119 OPEN orphanuser_cur
120 FETCH NEXT FROM orphanuser_cur INTO @UserName
121 WHILE (@@fetch_status = 0)
122 BEGIN
123 select @UserName + ' user name being resynced'
124 set @SQLCmd = 'ALTER USER '+@UserName+' WITH LOGIN = '+@UserName
125 EXEC (@SQLCmd)
126 FETCH NEXT FROM orphanuser_cur INTO @UserName
127 END
128 CLOSE orphanuser_cur
129 DEALLOCATE orphanuser_cur
130 ''&#x27;
131 # sqlcmd needs single line sql commands for the -Q option
132 s = s.replace("\n", ' ')
133 sqlsynclogins = 'SET NOCOUNT ON USE [' + db + '] ' + s
134 rows, fnames = [], []
135 try:
136 rows, fnames = SqlExecute(conn, sqlsynclogins)
137 except Exception as inst:
138 print('Error executing fix logins: ', inst)
139 return rows
140
141def DatedString():
142 """

Callers 2

recipe-578977.pyFile · 0.85
ActionParsingFunction · 0.85

Calls 3

SqlExecuteFunction · 0.85
printFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected