﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Programming / SMO/RMO/DMO  / sqlcmd.exe is hanging after running sql statement in inno package / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 12:10:24 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: sqlcmd.exe is hanging after running sql statement in inno package</title><link>http://www.sqlservercentral.com/Forums/Topic1192113-22-1.aspx</link><description>[quote][b]WaitingWonder2 (10/18/2011)[/b][hr]Hello,I'm write installation package using inno for ms sql script. I have the following code:[code="other"]      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;[/code]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.[/quote]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 /? &amp;gt; 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.</description><pubDate>Fri, 21 Oct 2011 08:58:52 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>sqlcmd.exe is hanging after running sql statement in inno package</title><link>http://www.sqlservercentral.com/Forums/Topic1192113-22-1.aspx</link><description>Hello,I'm write installation package using inno for ms sql script. I have the following code:[code="other"]      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;[/code]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.</description><pubDate>Tue, 18 Oct 2011 08:19:29 GMT</pubDate><dc:creator>WaitingWonder2</dc:creator></item></channel></rss>