We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

MikeA
Posts: 2
Joined: Fri May 03, 2019 3:12 am

Skip database file execution if db exists

I am new to AI and trying to figure one final part. During the install, I create a MSSQL Db. I can get everything to work fine on first install. However, I can't figure out how to handle the case when the application is uninstalled and reinstalled. I don't want to drop the db on uninstall. When reinstalling, it fails because the tables already exist in the db. I can add an if exists to every table in the script but there is a large number of tables and it does not seem like the best approach. Ideally, I would like a way to skip executing the SQL script file if the database already exists. I can't seem to find any information on how to do this. Any ideas?
Thanks
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Skip database file execution if db exists

Hello and welcome to our forums,

To achieve what you need you should just add the following condition on your scrip in "SQL Databases" page:

Code: Select all

(NOT Installed) AND (NOT OLDPRODUCTS)
This means the the SQL script will be executed only during the first time installation of the current setup package and only if the current installation is not upgrading an old version of the product.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
MikeA
Posts: 2
Joined: Fri May 03, 2019 3:12 am

Re: Skip database file execution if db exists

Thank you. This seems to cover it if the product was installed. However, if the database already exists, it still fails. So for instance, if the installer is run on a new server and pointed to an existing database, I want the installer to detect that the db exists and skip running the script. Can the installer detect this or do I need to handle in in SQL?
Thanks
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Skip database file execution if db exists

Hello,

To do so you should use an "SQL Query" to interrogate the SQL Server if the related database exists. The query result set (response) will be saved into an installer property (e.g. QUERY_PROP). You can use this property to condition the execution of the SQL Scripts that create the database.

Let us know if this is still of no help.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”