santoshinstaller
Posts: 7
Joined: Mon Aug 08, 2011 9:58 am

SQL Script

Hello,

I am using advance installer to install a web aplplication. I am executing the script as well as a part of my installation.
I want to add a check before executing the script whether the database with the specified name exists. If it does then the script should not be executed and installation should continue. The script should be executed only if the database is not present.

Is there any way to achieve this functionality?

I am using an old version of AI (5.1.1).

Thanks in advance.

Regards,
Santosh
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: SQL Script

Hi Santosh and welcome to Advanced Installer forums,

Here is another thread that debates this issue.

In your case the script's execution condition could be something like:

Code: Select all

NOT (DATABASE_PROP >< YOUR_DATABASE_NAME)
If you have any doubts, don't hesitate to contact us.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
santoshinstaller
Posts: 7
Joined: Mon Aug 08, 2011 9:58 am

Re: SQL Script

Hi Mihai,

Thanks for the prompt response. I tried the way you suggested but it did not work.
I will explain this a bit more. I am using SQL Scripts option. My database is SQL server. I am taking Server name, username and password from user by using SQLConnectionDlg. My database name is fixed and I am providing that in the textbox Database under Catalogue. I have also checked the checkbox "Create Database if not exists". Now as per the suggestion I have added the condition in Script condition. The condition added is "NOT (DATABASE_PROP >< InventoryManagement)". InventoryManagement is my database name. But when I build and install it is creating the DB everytime.

Can you please help me out?

Thanks in advance.

Regards,
Santosh
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: SQL Script

Hi Santosh,

This quote from your first post:
I want to add a check before executing the script whether the database with the specified name exists. If it does then the script should not be executed and installation should continue. The script should be executed only if the database is not present.
is contradictory with:
But when I build and install it is creating the DB everytime.
unless your script creates a database.

However, the following article describes how to show all available databases from the SQL Server. You can adapt it and use its output( SqlServerDatabases property for example ) to create your condition. In this case, the condition could be something like:

Code: Select all

NOT ( SqlServerDatabases >< "InventoryManagement" )
A flat, comma separated list of SQL databases (names only) will be dumped into the SqlServerDatabases property.

In my last post I was referring to the thread and the third case output scenario from the above article( linked in the thread ).

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
santoshinstaller
Posts: 7
Joined: Mon Aug 08, 2011 9:58 am

Re: SQL Script

Hi Mihai,

Thanks for the prompt reply. I think there is some mis-communication. Let us start from begining.
I have created a package that installs web project. During the installation I take Database name, Username and Password from the user. I have also included a database script in package. I have given the database name to create the database as part of AI package.All of this information has been provided as a part of package. My script does not check for Database existance.

Is it poissible to do this using AI. What really I am looking for is that AI should decide whether to execute the script by checking if the database with specified name exists. If it exists then AI project should take the action of not executing the script at all and go ahead.

Is it possible to handle this?

Thanks again for all the help.

Regards,
Santosh
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: SQL Script

Hi Santosh,

Now I understand what you meant by creating the database. Anyway, this was outside the thread topic.
Is it poissible to do this using AI. What really I am looking for is that AI should decide whether to execute the script by checking if the database with specified name exists. If it exists then AI project should take the action of not executing the script at all and go ahead.
Yes it is. Just try to follow this article which describes how to show all available databases from the SQL Server. You can adapt it and use its output( SqlServerDatabases property for example ) to create the condition for your script. In this case, the condition could be something like:

Code: Select all

NOT ( SqlServerDatabases >< "InventoryManagement" )
A flat, comma separated list of SQL databases (names only) will be dumped into the SqlServerDatabases property.

If you find any difficulties implementing this into a test project feel free to contact us.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”