(conn, db)
| 109 | return rows |
| 110 | |
| 111 | def 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 | ''' |
| 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 | |
| 141 | def DatedString(): |
| 142 | """ |
no test coverage detected