views:

346

answers:

2

I have written an installer and uninstaller in NSIS which creates and drops an sql database, which is working fine. I have written some .bat and .sql files to create and drop the database and then just call these files from NSIS script. My problem is if I keep this database open in SQL Server Management Studio and run the uninstaller ideally it should give an error message that the database is opened. In my case it shows the success message of uninstaller but dosnt drop the database properly. How can I handle this error in NSIS?

A: 

It depends on how you are calling these sql files from NSIS. Assuming you are using the SQL command line, you could use nsExec::ExecToStack to capture the output. Note the limitation on string length(which can be modified with one of the special builds of NSIS): http://nsis.sourceforge.net/Docs/nsExec/nsExec.txt

Check for error on the top of the stack, which indicates if the command line returned a non-zero return code. If there is no error, you still need to parse the output of the sql command to see if there were errors logged there. You may need to pass paramters to the sql command line to specify verbose error output and whatnot. That will be up to you to experiment with and see what scenarios produce what output. I normally log the output from ExecToStack so that I can go back and see after the fact what was returned.

AaronLS
A: 

Your .bat files should exit with a error code (such as 1). When you call the .bat (with ExecWait I presume) you can catch the return code. You then compare the return code with the error and call the SetErrors function if they're equals. I can give you an example code if you wish.

Silence