Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

sqlcmd.exe is hanging after running sql statement in inno package Expand / Collapse
Author
Message
Posted Tuesday, October 18, 2011 8:19 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, June 16, 2012 1:16 AM
Points: 14, 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.
Post #1192113
Posted Friday, October 21, 2011 8:58 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 10:47 AM
Points: 7,126, Visits: 12,727
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
Post #1194453
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse