【发布时间】:2014-05-27 21:17:51
【问题描述】:
在谷歌上搜索了一堆并挣扎了一天没有结果之后,我在这里。 我正在使用 Inno Setup 开发安装程序,它会根据来自包含复选框的向导页面的一些用户输入安装并正确配置 MS SQL Server 2008 R2。
我有一个过程来执行这样设置的 SQL Server 配置:
Source: ".\src\{#ExecName}"; DestDir: "{app}"; Flags: ignoreversion; AfterInstall: runSQLCMD
#ExecName 是我的 .exe 名称;
程序如下:
[Code]
procedure runSQLCMD();
var
ResultCode: Integer;
SQLCMDPath: String;
SQLParams: String;
BasicQuery: String;
FullQuery: String;
begin
SQLCMDPath := ExpandConstant('{pf}') + '\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe'
BasicQuery := 'EXEC sp_configure ''show advanced option'', 1; RECONFIGURE; EXEC sp_configure ''max worker threads'', 256; RECONFIGURE; EXEC sp_configure ''backup compression default'', 1; RECONFIGURE; EXEC sp_configure ''max degree of parallelism'', 4; RECONFIGURE; EXEC sp_configure ''max server memory'', 512; RECONFIGURE;';
FullQuery := 'EXEC sp_configure ''show advanced option'', 1; RECONFIGURE; EXEC sp_configure ''backup compression default'', 1; RECONFIGURE; EXEC sp_configure ''max degree of parallelism'', 4; RECONFIGURE; EXEC sp_configure ''max server memory'', 1024; RECONFIGURE;';
if not FileExists(SQLCMDPath) then begin
SQLCMDPath := ExpandConstant('{pf64}') + '\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe'
end;
if (ShouldRunItem(1)) then begin
SQLParams := '-S .\INSTANCE -U sa -P "password" -Q "' + BasicQuery + '-o ' + ExpandConstant('{tmp}') + '\logsql.txt';
if (Exec(SQLCMDPath, SQLParams, '',SW_SHOW,ewWaitUntilIdle, ResultCode)) then begin
MsgBox('Success!', mbInformation, MB_OK);
end
else begin
MsgBox('Error', mbError, MB_OK);
end;
end;
if (ShouldRunItem(2)) then begin
SQLParams := '-S .\INSTANCE -U sa -P "password" -Q "' + FullQuery + '-o ' + ExpandConstant('{tmp}') + '\logsql.txt';
if (Exec(SQLCMDPath, SQLParams, '',SW_SHOW,ewWaitUntilIdle, ResultCode)) then begin
MsgBox('Success!', mbInformation, MB_OK);
end
else begin
MsgBox('Error', mbError, MB_OK);
end;
end;
end;
当 Exec 语句运行时,ResultCode 变量在调试时返回零,但是当我右键单击服务器时,指向属性/内存(在 SSMS 上),内存配置未设置为用户选择的值。甚至没有生成 logsql.txt 文件(我已经打开了 {tmp} 常量指向的目录并且那里没有 .txt 文件)
从 cmd 运行 sqlcmd,使用相同的参数和查询,一切正常。
我做错了什么?
提前谢谢你。
【问题讨论】:
-
找到解决办法了吗?我遇到了同样的行为。
-
嗯...这是一个 7 年以上的老问题,我无法再访问此代码了。我想我确实想出了一些东西,但我不记得了。对此感到抱歉。
标签: sql sql-server installation inno-setup