我有一个NSIS脚本来复制.NET应用程序构建并在SQL DB上执行一些脚本。我在nsis中使用xsqlexecutor工具在捕获实例,数据库和登录等sql详细信息后运行这些脚本。当调用nsis自定义页面时,这些是从Windows注册表填充的。页面离开功能检查它是否可以成功连接到该数据库,如果它不能,它将中止离开功能并返回到页面。这里的问题是,当我第一次给出错误的详细信息时,保留功能中止并返回页面,但如果我再次提供正确的数据库详细信息,则表示xsqlexecutor已停止运行。但是,如果返回页面然后点击下一步并再次进入页面,如果我提供正确的数据库详细信息,它似乎正在工作,
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 :(得分: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