claudenoel
Posts: 17
Joined: Mon Oct 22, 2018 1:25 pm

Hot to execute SQL scripts on several databases

I need to run the same 3 SQL scripts (SQL1, SQL2 and SQL3) on 1 to 4 identical databases. The number of databases varies and is found by querying a DBMaster database : select Source_data from COMPANY. This query returns the name of the databases where the scripts should be executed.
There is at least 1 database found: LOCAL_1. But we can also have LOCAL_2, LOCAL_3 and LOCAL_4.
So, for each database found from the above query, I should run SQL1, SQL2 and SQL3 in this order. Il one of them fails, the installation should abort.

Any help is welcome!
Catalin
Posts: 7845
Joined: Wed Jun 13, 2018 7:49 am

Re: Hot to execute SQL scripts on several databases

Hello and welcome to our forums,

I am afraid that we do not have predefined support for your task.

However, you can try to achieve this through a custom action. For example, you can use a "Run inline PowerShell script".

I think you may find useful the following Microsoft article:

https://docs.microsoft.com/en-us/powers ... lserver-ps

Hope this helps.

Kind regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
claudenoel
Posts: 17
Joined: Mon Oct 22, 2018 1:25 pm

Re: Hot to execute SQL scripts on several databases

Ok. What about using a combobox?
I found the way to populate the combobox whith the existing databases. The user will have to select them one by one and press a button to execute the SQL scripts against the selected database.
Is there a way to execute the same script by replacing the USE satatement of the SQL script with the combobox selected database name or do I need to create 4 différents connections with separate SQL scripts?
claudenoel
Posts: 17
Joined: Mon Oct 22, 2018 1:25 pm

Re: Hot to execute SQL scripts on several databases

Forget it, I found the solution with the script replacements. and it works fine!

Thanks for your help anyway ;-)
Catalin
Posts: 7845
Joined: Wed Jun 13, 2018 7:49 am

Re: Hot to execute SQL scripts on several databases

You're always welcome.

I am glad you got this working.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”