VSDBCMD.EXE Return Codes

Quick one based on a forum question where somebody asked how to detect if VSDBCMD.EXE failed or succeeded inside a batch file.

VSDBCMD.EXE does not return a very elaborate amount of information, there are just two return values 0 and 1, where zero indicates success and 1 failure. So in order to test for this you simply check the ERRORLEVEL inside your batch file.

This is a simple wrapper that I use that shells out to VSDBCMD.EXE and passes all the parameters, so I do not have to place the Deploy directory on the PATH.

   1:  @echo off
   2:  setlocal
   4:  if "%PROCESSOR_ARCHITECTURE%"=="x86" call "%ProgramFiles%\Microsoft Visual Studio 9.0\VSTSDB\Deploy\vsdbcmd.exe" %*
   5:  if "%PROCESSOR_ARCHITECTURE%"=="AMD64" call "%ProgramFiles(x86)%\Microsoft Visual Studio 9.0\VSTSDB\Deploy\vsdbcmd.exe" %*
   7:  if errorlevel 1 @echo vsdbcmd.exe failed&goto end
   8:  if errorlevel 0 @echo vsdbcmd.exe succeeded&goto end
  10:  endlocal
  12:  :end

The checks for PROCESSOR_ARCHITECTURE make sure I can find the executable in the right location depending on the fact if I am running with a x32 or x64 CMD.EXE instance.

Also published on: http://www.dbproj.com/Tutorials/tabid/62/TID/16/cid/21/Default.aspx

Have fun,

GertD @ www.DBProj.com

Comments (2)
  1. dev3001 says:

    Your blog is very helpful. I’ve also done a blog post in general on tracking down errors that show up during a VSDB deploy (vs a build), since you often get errors while debugging post deployment scripts and they can be elusive to track down.


  2. Dav says:

    Gert – Im having trouble with vsdbcmd not returning 1 when an error occurs inside my generated sql file during deployment. I'm using the  RC of vs2010. Does the RC of vs2010 suffer from the issue fixed here: http://support.microsoft.com/kb/970595/ ?

Comments are closed.

Skip to main content