We are trying to automate a backup of our imis database (imis) and restore to a different database (imisYesterday) nightly. We are on version 10.6 and running SQL 2005 in SQL 2000 compatibility mode. The backup and restore is no problem (using the code below), but what we’re having problems with is the logins are now broken for the restored database. In iMIS under system setup, User Passwords, there are two buttons – Update All SQL Logins and Re-Create All SQL Logins - which will fix this problem but we need this to happen automatically. Are these buttons accessing a stored procedure within iMIS that we can call or is there code that has been written to accomplish this?
BACKUP DATABASE [imis]
TO DISK = N'D:\restore\imis.bak'
WITH NOFORMAT,
INIT,
NAME = N'Full backup',
SKIP,
NOREWIND,
NOUNLOAD,
STATS = 10
GO
--Drops connections to imisYesterday
ALTER DATABASE imisYesterday SET SINGLE_USER WITH ROLLBACK IMMEDIATE
--Database restore
RESTORE DATABASE [imisYesterday]
FROM DISK = N'D:\restore\imis.bak'
WITH FILE = 1,
MOVE N'imis_Data' TO N'C:\MSSQL\DATA\imisYesterday_Data.mdf',
MOVE N'imis_Log' TO N'C:\MSSQL\DATA\imisYesterday_log.ldf',
NOUNLOAD,
REPLACE,
STATS = 10
GO
try sp_asi_CreateLogins...
...it does most of the work in 10.6. There may be some additional SQL necessary, depending on your security model.