0

This is my code. I want to get only 0 if the database connection is successfully else 1. But sqlplus.exe always returns 0.

I call the file sqlplus with the parameter user,password and databasename. After this i try to get the exit code which should be 0 if the connection was successfully but it always returns 0

call exit | C:\app\client\sahi\product\12.1.0\client_1\BIN\sqlplus.exe
%DBUser%/%DBPassword%@%DBName% 
if errorlevel 0 (
                 echo successfull
                 goto success
                )

How can i do this?

nobody
  • 19,814
  • 17
  • 56
  • 77
  • 1
    `IF ERRORLEVEL 0` means "if errorlevel is zero or greater": http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/if.mspx?mfr=true you need a `if errorlevel 1 goto failure` –  May 13 '14 at 11:40
  • The return value always is 0 it is independent of succesful/unsuccessful connectivity. – user3632179 May 13 '14 at 12:25
  • If you check like that, then yes the value will always *appear* to be zero. –  May 13 '14 at 12:26
  • how can i check the connectivity ? have you got a idea ? – user3632179 May 13 '14 at 13:23
  • possible duplicate of [Sql\*plus always return exit code 0?](http://stackoverflow.com/questions/18111517/sqlplus-always-return-exit-code-0) – Álvaro González May 13 '14 at 15:49

1 Answers1

0

This is one way to check for errorlevel 0:

if not errorlevel 1 (
                 echo successfull
                 goto success
                    )
foxidrive
  • 40,353
  • 10
  • 53
  • 68