cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Azmaeus
Level 6

SQL Connection Error Handling

I'm trying to drop SQL databases on uninstall, because I couldn't get a SQL Uninstall to happen from within my uninstall (if anyone can help with this instead, it would be preferred). I created a connection and script within SERVER CONFIGURATION > SQL Scripts that drops the databases created during install. The issue I'm running into is that if there is something wrong and either the connection to the SQL server can't be established, or the databases can't be found, I get an error.

In the event the SQL server can be connected to, but perhaps one or both of the databases were already removed, I'm getting an error even though I added a check within SQL to skip the statement if the database doesn't exist. I'm trying configurations in Script Error Handling to see if that handles this error.

The issue I'm struggling with is when the SQL server connection can't be established I get an error "Error 27502. Could not connect to Microsoft SQL Server '<server>\<instance>'. Login timeout expired (0)" with only an "OK" button. Once the OK button is pressed, a rollback occurs, and the product remains installed. If there's no way to connect to the SQL server, there's no way to uninstall the product. This is not ideal, I'd like to configure the uninstall to resume if it can't connect to SQL, or if it can and can't find the databases. Thanks!

Labels (1)
0 Kudos
(1) Reply
ch_eng2
Level 6

I don't know if this is an option for you, but in our InstallScript Only project, when we uninstall (or abort a failed install with new database), we delete the database via InstallScript and ADODB. 

Example of ADODB connection via InstallScript:

https://stackoverflow.com/questions/44691845/create-sql-connection-using-install-script-in-installshield-project

Example script to run to delete the database:

strSQL = "IF DB_ID('" + YOUR_DB_NAME + "') IS NOT NULL " +
"BEGIN " +
" ALTER DATABASE [" + YOUR_DB_NAME + "] SET SINGLE_USER WITH ROLLBACK IMMEDIATE " +
" DROP DATABASE [" + YOUR_DB_NAME + "] " +
"END";


(based on http://sarafianalex.wordpress.com/2007/12/28/close-database-connections-from-t-sql/ )

You can run that code within an "if" statement in InstallScript and choose to continue or not with the rest of your install/uninstall if the SQL code fails.

HTH

0 Kudos