SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


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


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

Author
Message
WaitingWonder2
WaitingWonder2
SSC-Enthusiastic
SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)

Group: General Forum Members
Points: 156 Visits: 73
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.
Orlando Colamatteo
Orlando Colamatteo
SSC Guru
SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)SSC Guru (78K reputation)

Group: General Forum Members
Points: 78930 Visits: 14499
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search