October 18, 2011 at 8:19 am
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.
October 21, 2011 at 8:58 am
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
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy