Restoring new database using Inline SQL Script - Advanced Installer Community
BCh
Posts: 63
Joined: Wed Jan 17, 2007 6:32 am
Location: Australia

Restoring new database using Inline SQL Script

Am looking at trying to install a new SQL database as part of a new install.

I have a silent install of SQL 2014 working as a pre-requisite successfully in Advanced Installer.

From within advanced Installer - Server | SQL Databases am looking at executing the inline script to RESTORE DATABASE myDataBase FROM DISK = 'C:\ProgramData\MyCompany\myDataBase.bak' plus some other db commands.

During the install the restore command of the database is NOT working.

That part of the script is "Missed" (and does not abort even though I have On Error abort) and the script then fails on the next inline script db commands saying that myDataBase does not exist.

If I manually do the Restore from within SQL Management Studio (i.e. outside Advanced Installer) and run the install all works OK i.e. the additional db commands work successfully.

Any suggestions.

Brian
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Restoring new database using Inline SQL Script

Hi Brian,

To restore a database, please follow these steps:

1)In the Files and Folders view, add the .bak file in a regular folder created under the Common Application Data as you can see below:
Files and Folders view.png
Files and Folders view.png (18.97 KiB) Viewed 8034 times
2) In the SQL Database view, add a .sql script that will perform the restore operation under your connection.

Please use a property for the path of the .bak file, as you can see below:
RestoreDBScript.png
RestoreDBScript.png (30.05 KiB) Viewed 8034 times
3) In the Script Replacements Tab, create a replace operation to set the property with the path of the .bak file as you can see below:
SQL Replace tab.png
SQL Replace tab.png (10.33 KiB) Viewed 8034 times
So, during installation, the property (in our case MY_DATABASE_PATH) will be set with the path of the .bak file (in our case myDataBase.bak).

Please let me know if you have any questions.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
BCh
Posts: 63
Joined: Wed Jan 17, 2007 6:32 am
Location: Australia

Re: Restoring new database using Inline SQL Script

Dan,

A bit delayed but thanks for comment.

It set me on the right path and install now working.

Brian
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Restoring new database using Inline SQL Script

You're welcome Brian,

If there is anything else I can help you with, please let me know.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
francis.matamoros
Posts: 15
Joined: Fri Mar 23, 2018 7:39 pm

Re: Restoring new database using Inline SQL Script

Hello, I've done everything you say in the answer, but now I do not know how to call the script. If I use a custom action, nothing appears but the connection in "Choose SQL Script", but I do not get the script below.
I would swear that on some occasion I managed to do it, but I do not remember how it was, and I have not saved the project where I did it.
Thank you.

See image, please.
Captura.JPG
Captura.JPG (74.39 KiB) Viewed 6307 times
Captura.JPG
Captura.JPG (60.04 KiB) Viewed 6307 times
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Restoring new database using Inline SQL Script

Hello Francis,

You can not pick the earlier created script, because you are trying to pick it using an SQLQueryAction custom action. Please let me try to explain what are the main differences between a script and a query:

- A script is scheduled during the "Install Execution Stage" (on deferred). They are ran in the order specified in "SQL Databases" page --> "Database server" section.

- A query can be scheduled anywhere during the "Wizard Dialogs Stage" or "Install Execution Stage" (both "Immediate" and "Deferred").

With that being said, if you want to manually schedule the custom action, please create a query instead of a script in "SQL Databases" page.

Hope this helps.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
francis.matamoros
Posts: 15
Joined: Fri Mar 23, 2018 7:39 pm

Re: Restoring new database using Inline SQL Script

Thanks, I will check that it works
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Restoring new database using Inline SQL Script

You're welcome, Francis.

Kind regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”