Pause query with exit or continue option

Last Post 29 Mar 2010 10:28 PM by dennebom. 0 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
New Member
New Member

29 Mar 2010 10:28 PM
Hello, I've got an t-sql script that i'm running in sqlcmd.
This script must run an different environments. Therefor I've made a special connect script. When I connect to sqlcmd, I run my script like this, :r script.sql. The script includes the connect.sql script and in the sqlcmd prompt I see the following: Sqlcmd: Succesfully connected to server 'SQLSERVER2005'.
When I put :!! PAUSE after the :CONNECT in the connect.sql, sqlcmd waits till you press any key to continue. I want this to verify if the script made the right connection. If I see that the connection is wrong I want to abort the script. CTRL-C or CTRL-BREAK won't work.

:setvar SERVER "SQLSERVER2005"


:setvar delta "script"
:setvar server "connect.sql"
:setvar dbname "master"

:out $(delta).lst

:r $(server)

use $(dbname)

-- insert or update scripts

Acceptable Use Policy