sqlcmd.exe is hanging after running sql statement in inno package

  • Hello,

    I'm write installation package using inno for ms sql script. I have the following code:

    strParam := '-U hel -P password -S ServerName -d test -Q "sp_test"';

    try

    Exec('sqlcmd.exe', strParam, '', SW_SHOW, ewWaitUntilTerminated, ResultCode);

    result := ResultCode = 0;

    except

    Exec('osql.exe', strParam, '', SW_SHOW, ewWaitUntilTerminated, ResultCode);

    result := ResultCode = 0;

    end;

    Sp executes ok but black screen with sqlcmd.exe is hanging until either I type exit or close it. I want a window with sqlcmd.exe closed after sp is executed.

  • WaitingWonder2 (10/18/2011)


    Hello,

    I'm write installation package using inno for ms sql script. I have the following code:

    strParam := '-U hel -P password -S ServerName -d test -Q "sp_test"';

    try

    Exec('sqlcmd.exe', strParam, '', SW_SHOW, ewWaitUntilTerminated, ResultCode);

    result := ResultCode = 0;

    except

    Exec('osql.exe', strParam, '', SW_SHOW, ewWaitUntilTerminated, ResultCode);

    result := ResultCode = 0;

    end;

    Sp executes ok but black screen with sqlcmd.exe is hanging until either I type exit or close it. I want a window with sqlcmd.exe closed after sp is executed.

    You can do this by invoking the cmd shell using the /C switch. You may need to rework your code to allow for the change in cmomand line structure however.

    Try running this from the Run prompt and you'll see what I mean:

    cmd /C "sqlcmd.exe /? > C:1.txt"

    As a side note...you have a potential latent bug in your code. It's not a good idea to use exceptions as a control flow mechanism. If you call to sqlcmd.exe does some work in the database but still exits with an error you could potentially run some database commands a second time with the call using osql in your except block. I would recommend employing a different approach to determining when to osql versus sqlcmd.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply