ggrewe
07-23-2008, 03:15 PM
I have a Basic MSI (IS2009). There is an Installscript Custom Action that will attach a database to SQL Express 2005 and add some users. I am having two problems;
1. The CA runs, but the SQL Script is not executed successfully. The command window opens and closes way to fast to read anything. I can run the identical code from a CMD prompt and it completes successfully.
2. The Status window does not close after the CA runs. I have to kill it through task manager.
Notes:
The Custom Action is set for Immediate Execution, the sequence is after InstallFinalize.
InstallScript:
export prototype AttachDB(HWND);
function AttachDB(hMSI)
STRING szMsg, szProgram, szCmdLine;
NUMBER nReturn;
begin
szProgram = "SQLCMD.EXE";
szCmdLine = "-S localhost\sqlexpress -d master -E -i c:\temp\data\AttachEXDB.sql -o c:\temp\data\AttachEXDB.log";
szMsg = "Attaching database named c:\temp\data\local_820_ng on LOCALHOST\SQLEXPRESS. Please wait...";
nReturn = SdShowMsg(szMsg, TRUE);
// nReturn = LaunchAppAndWait(szProgram, szCmdLine, LAAW_OPTION_WAIT | LAAW_OPTION_MINIMIZED | LAAW_OPTION_SHOW_HOURGLASS);
nReturn = LaunchAppAndWait(szProgram, szCmdLine, LAAW_OPTION_NOWAIT );
if (nReturn < 0) then
SdShowMsg(szMsg,FALSE);
SprintfBox (SEVERE, "Aborting Installation","Error in running %s %s", szProgram, szCmdLine);
abort;
endif;
end;
SQL Script:
USE [master]
GO
CREATE DATABASE [LOCAL_820_NG] ON
( FILENAME = N'C:\Temp\data\LOCAL_820_NG.mdf' )
FOR ATTACH
GO
if exists (select name from master.sys.databases sd where name = N'LOCAL_820_NG' and SUSER_SNAME(sd.owner_sid) = SUSER_SNAME() ) EXEC [LOCAL_820_NG].dbo.sp_changedbowner @loginame=N'sa', @map=false
GO
CREATE LOGIN LOCAL_820_NG WITH PASSWORD = '820_NG', DEFAULT_DATABASE = LOCAL_820_NG
GO
use [LOCAL_820_NG]
GO
CREATE USER LOCAL_820_NG FOR LOGIN lOCAL_820_NG
GO
sp_addrolemember @rolename = 'db_Owner' , @membername = 'LOCAL_820_NG'
1. The CA runs, but the SQL Script is not executed successfully. The command window opens and closes way to fast to read anything. I can run the identical code from a CMD prompt and it completes successfully.
2. The Status window does not close after the CA runs. I have to kill it through task manager.
Notes:
The Custom Action is set for Immediate Execution, the sequence is after InstallFinalize.
InstallScript:
export prototype AttachDB(HWND);
function AttachDB(hMSI)
STRING szMsg, szProgram, szCmdLine;
NUMBER nReturn;
begin
szProgram = "SQLCMD.EXE";
szCmdLine = "-S localhost\sqlexpress -d master -E -i c:\temp\data\AttachEXDB.sql -o c:\temp\data\AttachEXDB.log";
szMsg = "Attaching database named c:\temp\data\local_820_ng on LOCALHOST\SQLEXPRESS. Please wait...";
nReturn = SdShowMsg(szMsg, TRUE);
// nReturn = LaunchAppAndWait(szProgram, szCmdLine, LAAW_OPTION_WAIT | LAAW_OPTION_MINIMIZED | LAAW_OPTION_SHOW_HOURGLASS);
nReturn = LaunchAppAndWait(szProgram, szCmdLine, LAAW_OPTION_NOWAIT );
if (nReturn < 0) then
SdShowMsg(szMsg,FALSE);
SprintfBox (SEVERE, "Aborting Installation","Error in running %s %s", szProgram, szCmdLine);
abort;
endif;
end;
SQL Script:
USE [master]
GO
CREATE DATABASE [LOCAL_820_NG] ON
( FILENAME = N'C:\Temp\data\LOCAL_820_NG.mdf' )
FOR ATTACH
GO
if exists (select name from master.sys.databases sd where name = N'LOCAL_820_NG' and SUSER_SNAME(sd.owner_sid) = SUSER_SNAME() ) EXEC [LOCAL_820_NG].dbo.sp_changedbowner @loginame=N'sa', @map=false
GO
CREATE LOGIN LOCAL_820_NG WITH PASSWORD = '820_NG', DEFAULT_DATABASE = LOCAL_820_NG
GO
use [LOCAL_820_NG]
GO
CREATE USER LOCAL_820_NG FOR LOGIN lOCAL_820_NG
GO
sp_addrolemember @rolename = 'db_Owner' , @membername = 'LOCAL_820_NG'