Umarlone
Posts: 20
Joined: Mon Oct 23, 2017 7:15 pm

SQL Server Connection create database and run script

Hello There,
Here is what I am trying to do:
I have inbuilt SQLConnection dialog which is providing mechanism to test where user and password is correct and lists the databases on a given sql server. Its working great. Now before that dialog comes up I want to provider user a dialog where user can enter user password and server address, first on test connection it test if credentails ok then I want to run SQL script which basically simple SQL commands to create tables if database doesnt exist it creates one. I was following the tutorials but I got lost at "Adding ODBC driver" and ddls, and how to trigger that event. Can you please help me in a direction?


Thanks

Raj
Dan
Posts: 4513
Joined: Wed Apr 24, 2013 3:51 pm

Re: SQL Server Connection create database and run script

Hello Raj,

From my understanding you are using our predefined SQLServerConnectionDlg.Since you wish to test the credentials before executing the script there is no need for another dialog.You can do this from your current dialog, there is no need of a new dialog.

Simply go to the SQLServerConnectionDlg and the Next button --> Published Events and click New.
Depending on your SQL Server type you will have to set the following event:

Set Installer property
Property:SqlConnectionString
Argument:Driver=[\{]SQL Server[\}];Server=[SERVER_PROP]; PORT=[PORT_PROP];Uid=[USERNAME_PROP];Pwd=[PASSWORD_PROP];
Condition:1

What differs on this event from one SQL Server to another is the "Driver" and the fact that Prostgres SQL servers have another field called [DATABASE_PROP].
Please have a look at the following article for more details How to test SQL connection parameters. A very important note when using ODBC drivers to test the connection is that Advanced Installer can only support 32 bit ones.

Now you need to test the actual connection using another event.
In the Published Events of the Next button, you will have to add the following event as well:

Execute Custom Action
Argument:TestODBCConnection
Condition:1

The order of these events should be as depicted in the screenshot.
PublishedEventsOrder.PNG
PublishedEventsOrder.PNG (34.06 KiB) Viewed 3809 times
I have also attached a sample project made using these exact steps. Please note that it was made for a MS SQL Server.

Best regards,
Dan
Attachments
Sample Project.rar
(3.93 KiB) Downloaded 326 times
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Umarlone
Posts: 20
Joined: Mon Oct 23, 2017 7:15 pm

Re: SQL Server Connection create database and run script

Hello, arent you sweet? :), makes sense. I will check the project, and yes I am using SQL Server. This is huge help. The thing that makes your project awesome is the support you have...Thank you
Umarlone
Posts: 20
Joined: Mon Oct 23, 2017 7:15 pm

Re: SQL Server Connection create database and run script

Why on some dialogs Next button text changes to INSTALL?
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: SQL Server Connection create database and run script

Hello,

This may happen if the next dialog in sequence will be "ProgressDlg". Each dialog which will be followed by the "ProgressDlg" dialog changes the Next button label into "Install". This happens when using our "Surface" theme.

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

Return to “Common Problems”