Windows Installer, Java Installer, Freeware Installer
Home|Contact|Site Map|TOC|Search
Download  Features   Java  Licensing  Purchase  Testimonials  Support  Forums

How to test SQL connection parameters?

Answer

When using the SQL Scripts functionality and you require to prompt the user for ODBC connection parameters (for an ODBC driver), you might want to test if the connection works before proceeding. This will prevent an installation rollback due to incorrect connection parameters when executing the SQL scripts.

Dialog editorGo to the Dialog Editor page.

Add dialogAdd the Advanced Installer "SQLConnectionDlg" to the dialogs tree.

Select the [ Next ] button from this dialog and go to the Published Events tab and add a new "SetProperty" Published Event with the following parameters (E.g. for MS SQL Server):

  • Name: [SqlConnectionString]
  • Argument: Driver=[\{][ODBC_RES_PROP][\}];Server=[SERVER_PROP];Port=[PORT_PROP];Uid=[USERNAME_PROP];Pwd=[PASSWORD_PROP];
  • Condition: 1 (it will be shown as AI_INSTALL)

SQL Connection String control event

Connection Timeout

Optionally, you can specify a connection timeout (in seconds) for this test. The default is 60 seconds. The timeout can be specified through the Windows Installer property SqlConnectionTimeout. You can set this property statically (from Install Parameters), or dynamically (from the installer UI - associated with an Edit Control, or with a SetProperty Control Event).

TipYou can suppress the spawned message box for the connection test operation by setting the SqlSuppressSpawnMsgBox property to 1 . You can set this property statically (from Install Parameters), or dynamically (from the installer UI - associated with an Edit Control, or with a SetProperty Control Event).

Custom actions Go to the Custom Actions page and add the predefined UI Custom Action "Test ODBC Connection".

Test ODBC Connection CA

Return to Events Editor tab (Dialog Editor view) and add a new published event on the same [ Next ] button:

  • Name: DoAction
  • Argument: TestODBCConnection (the custom action name you create earlier)
  • Condition: NOT (SqlConnectionString = "")

DoAction control event

Edit the existing NewDialog published event on this button and set its condition to: SqlConnectionOK = "1". This will prevent the installation wizard to continue if the connection parameters are incorrect.

All control events

TipIf the entered connection parameters are incorrect a message box will display the detailed error information (ODBC Driver response).

ImportantThis testing functionality will work only in the case of a pre-existing ODBC driver (because at this stage of the installation the ODBC drivers installed by the package are not available yet).

NoteSee also: Browse for SQL Servers

Privacy Policy | Windows Installer | Search Engine Ranking | Link Analyzer