2015-10-16 16 views
0

我有一個NSIS腳本來複制一個.NET應用程序生成並在SQL DB上執行一些腳本。在nsis中使用xsqlexecutor工具在捕獲諸如實例,數據庫和登錄名之類的SQL細節之後運行這些腳本。當nsis自定義頁面被調用時,這些從Windows註冊表中填充。頁面離開功能檢查它是否可以成功連接到這個數據庫,如果不能,它會中止離開功能並返回到頁面。這裏的問題是,當我第一次給出錯誤的細節時,離開功能中止並且回到頁面,但如果我再次提供正確的數據庫細節,它說xsqlexecutor已停止運作。但是,如果回去頁面,然後點擊下一步,來到該頁面又似乎是工作,如果我給正確的DB細節,NSIS:從頁面離開功能中止後的頁面中的錯誤

Function SqlConfigPage 
     SectionGetFlags ${SEC03} $R0 
     IntOp $R0 $R0 & ${SF_SELECTED} 
     IntCmp $R0 ${SF_SELECTED} show 
     Abort 

show: 
nsDialogs::Create /NOUNLOAD 1018 
Pop $Dialog 
${If} $Dialog == error 
    Abort 
${EndIf} 
${NSD_CreateLabel} 0 0 100% 15u "Enter SQL Details" 
    Pop $Label 

    ${NSD_CreateLabel} 0 15u 50u 12u "Server Instance" 
    Pop $Server 

    ${NSD_CreateText} 60u 15u 100% 12u "$instance" 
    Pop $instance 

    ${NSD_CreateLabel} 0 30u 36u 12u "SQL DB" 
    Pop $dblabel 

    ${NSD_CreateText} 36u 30u 100% 12u "$db" 
    Pop $db 

    ${NSD_CreateLabel} 0 45u 36u 12u "Username" 
    Pop $userlabel 

    ${NSD_CreateText} 36u 45u 100% 12u "$user" 
    Pop $user 

    ${NSD_CreateLabel} 0 60u 36u 12u "Password" 
    Pop $Passwordlabel 

    ${NSD_CreatePassword} 36u 60u 100% 12u "$pwd" 
    Pop $pwd 
       nsDialogs::Show 

FunctionEnd 

Function SqlConfigPageLeave 

${NSD_GetText} $Server $R1 
${NSD_GetText} $db $R2 
${NSD_GetText} $user $R3 
${NSD_GetText} $pwd $R4 
StrCpy $server $R1 
StrCpy $db $R2 
StrCpy $user $R3 
StrCpy $pwd $R4 

InitPluginsDir 
SetOutPath "$PLUGINSDIR" 
SetOverwrite On 
    CreateDirectory $PLUGINSDIR\SQL 
    SetOutPath "$PLUGINSDIR\SQL" 
    File /nonfatal "..\xsql.exe" 
    File /nonfatal "..\sqlconnectioncheck.txt" 
    nsExec::Exec '$PLUGINSDIR\SQL\xsql.exe /s:$R1 /d:$R2 /t:false /u:$R3 /p:$R4 /m:3 /q /f:"$PLUGINSDIR\SQL\sqlconnectioncheck.txt"' 
    IfFileExists $PLUGINSDIR\SQL\ScriptErr.txt sqlerror continue 
sqlerror: 
FileOpen $7 "$PLUGINSDIR\Scripts\ScriptErr.txt" r 
FileRead $7 $8 
FileRead $7 $9 
FileClose $7 
    MessageBox MB_OK "SQL Connetion failed, check SQL details provided once again. $8 $9" 

continue: 
FunctionEnd 

任何投入將是有益的,非常感謝提前..

+0

我沒有看到任何呼叫在SqlConfigPageLeave功能中止! – Anders

回答

0

看來,你是重寫控制手柄在-Leave功能:

StrCpy $server $R1 
StrCpy $db $R2 
StrCpy $user $R3 
StrCpy $pwd $R4 

因此,在第二次調用你總是在垃圾桶參數:

${NSD_GetText} $Server $R1 
${NSD_GetText} $db $R2 
${NSD_GetText} $user $R3 
${NSD_GetText} $pwd $R4 

由於$ Server,$ db,$ user,$ pwd包含以前的值而不是控制句柄。

的控件使用單獨的變量及其價值,這樣的事情:

Var server_ctrl 
Var db_ctrl 
Var user_ctrl 
Var pwd_ctrl 
    Function SqlConfigPage 
      SectionGetFlags ${SEC03} $R0 
      IntOp $R0 $R0 & ${SF_SELECTED} 
      IntCmp $R0 ${SF_SELECTED} show 
      Abort 

    show: 
nsDialogs::Create /NOUNLOAD 1018 
Pop $Dialog 
${If} $Dialog == error 
    Abort 
${EndIf} 
${NSD_CreateLabel} 0 0 100% 15u "Enter SQL Details" 
    Pop $Label 

    ${NSD_CreateLabel} 0 15u 50u 12u "Server Instance" 
    Pop $Server_ctrl 

    ${NSD_CreateText} 60u 15u 100% 12u "$instance" 
    Pop $instance 

    ${NSD_CreateLabel} 0 30u 36u 12u "SQL DB" 
    Pop $dblabel 

    ${NSD_CreateText} 36u 30u 100% 12u "$db" 
    Pop $db_ctrl 

    ${NSD_CreateLabel} 0 45u 36u 12u "Username" 
    Pop $userlabel 

    ${NSD_CreateText} 36u 45u 100% 12u "$user" 
    Pop $user_ctrl 

    ${NSD_CreateLabel} 0 60u 36u 12u "Password" 
    Pop $Passwordlabel 

    ${NSD_CreatePassword} 36u 60u 100% 12u "$pwd" 
    Pop $pwd_ctrl 
       nsDialogs::Show 

FunctionEnd 

Function SqlConfigPageLeave 

${NSD_GetText} $Server_ctrl $R1 
${NSD_GetText} $db_ctrl $R2 
${NSD_GetText} $user_ctrl $R3 
${NSD_GetText} $pwd_ctrl $R4 
StrCpy $server $R1 
StrCpy $db $R2 
StrCpy $user $R3 
StrCpy $pwd $R4 

InitPluginsDir 
SetOutPath "$PLUGINSDIR" 
SetOverwrite On 
    CreateDirectory $PLUGINSDIR\SQL 
    SetOutPath "$PLUGINSDIR\SQL" 
    File /nonfatal "..\xsql.exe" 
    File /nonfatal "..\sqlconnectioncheck.txt" 
    nsExec::Exec '$PLUGINSDIR\SQL\xsql.exe /s:$R1 /d:$R2 /t:false /u:$R3 /p:$R4 /m:3 /q /f:"$PLUGINSDIR\SQL\sqlconnectioncheck.txt"' 
    IfFileExists $PLUGINSDIR\SQL\ScriptErr.txt sqlerror continue 
sqlerror: 
FileOpen $7 "$PLUGINSDIR\Scripts\ScriptErr.txt" r 
FileRead $7 $8 
FileRead $7 $9 
FileClose $7 
    MessageBox MB_OK "SQL Connetion failed, check SQL details provided once again. $8 $9" 

continue: 
FunctionEnd 
+0

非常感謝,這實際上解決了問題! – RKB83