Hi and welcome to our forums.
In order to achieve this you can simply add a condition in your scripts, so that they will be executed only if the database exists as in the example below:
Code: Select all
IF EXISTS(SELECT * FROM master.sys.sysdatabases WHERE name='DatabaseName')
BEGIN
<your SQL script code
END
Another method is to select each of your backup, install and restore database scripts and set the appropriate condition for them using some search properties.
In order to search if a database exists you can use one of the following solutions:
1. The recommended way is to
create a script that queries the database and run it in the "
SQL Query" tab from the "SQL Databases" page under a database connection. For example:
Code: Select all
SELECT * FROM dbo.sysdatabases WHERE name = 'DatabaseName'
In the "Data Binding" section add a property for each result of the query (i.e. if the query returns three values you can add three properties; if you add one property, only the first result will be stored, i.e. DATABASE_NAME).
You can use the "Schedule Action" blue link and schedule this query to run before the "Add Resources" action group from the "Custom Actions" page. If the data binding property contains a value it means that the database exists, otherwise it is not installed.
2. The second method it to add a "
Browse SQL Database" action, click on the "Show advanced options" blue link and "Put the result into a property" that you desire (i.e. FOUND_DATABASES). A flat, comma separated list of the available databases (names only) will be dumped into this property, so you can use the following condition to make sure that your database exists:
FOUND_DATABASES >< "DatabaseName" (TRUE if the property contains the right string).
3. Another way to determine if a database is installed is to do a "File search/Registry search" for the file or the registry that contains the database. Just go to "Search" page in the "Custom Behavior" section and use the "
New File Search" toolbar button. You can rename the result property according to the search you perform (i.e. DATABASE_EXISTS).
Let me know if this helped, otherwise give me more details about your scenario.
Best regards,
Eusebiu
FOLLOW US
Get the latest news in Application Packaging