【问题标题】:sqlcmd not working inside inno setup even with result code equals zero即使结果代码为零,sqlcmd 也无法在 inno 设置中工作
【发布时间】: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


【解决方案1】:

在我的情况下,它没有运行,因为我在 SQLCMDPath 变量周围添加了“”。一旦我删除它们, -Q 就成功执行了。另外,我使用 {commonpf} 而不是 {pf} := ExpandConstant('{commonpf}\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe');

完整代码

procedure CurStepChanged(CurStep: TSetupStep);
var
sqlCmd: String;
dbCreate: String;
path: String;
ResultCode: Integer;
begin
  path := ExpandConstant('{app}');
  sqlCmd := ExpandConstant('{commonpf}\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe');
  dbCreate := ' -S .\IVA -U sa -P sql -Q "CREATE DATABASE pos ON PRIMARY (NAME = N''pos'', FILENAME = N''' + path + '\pos.mdf'', SIZE = 73728KB, MAXSIZE = UNLIMITED ,FILEGROWTH = 65536KB) LOG ON (NAME = N''pos_log'', FILENAME = N''' + path + '\pos_log.ldf'', SIZE = 73728KB, MAXSIZE = 2048GB,FILEGROWTH = 65536KB)" -o "' + ExpandConstant('{app}\install.log') + '"';
  // CurStep values
  // ssInstall, ssPostInstall, ssDone
  if CurStep = ssPostInstall then begin
    // use log to view and test the string in a command window
    Log('The Value is dbCreate: ' + dbCreate );

    //MsgBox(sqlCmd + dbCreate, mbConfirmation, MB_YESNO)

      if Exec(sqlCmd, dbCreate, '' , SW_HIDE, ewWaitUntilIdle, ResultCode) then
        begin
          MsgBox( 'Database is ready for use' , mbInformation, mb_Ok);
        end
      else begin
        MsgBox(SysErrorMessage(ResultCode) , mbInformation, mb_Ok);
      end;
      
  end;
end;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-11
    • 1970-01-01
    • 2019-11-24
    • 2014-02-20
    • 2018-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多