SQL Custom Connection (ISqlCustomConnection)

Overview

The SQL Custom Connection represents a database connection that you can fully configure by specifying its type, connection string, and execution behavior. Unlike predefined or SQLite connections, a custom connection lets you target any supported database provider through ODBC, OLE DB, or other drivers.

Under a custom connection, you can add SQL Queries (parameterized or inline statements) and SQL Scripts (inline text or external files). At install time, Advanced Installer executes these operations using the connection string and options you define. Custom connections also support error logging, verbose output, and conditional execution.

This object is created through SqlDatabasesComponent.NewCustomConnection and appears in the SQL Databases page in Advanced Installer.

Isqldatabasescomponent custom connection

Methods

  • NewQuery (string name) -> ISqlQuery Creates a new SQL query under this custom connection with the specified display name. Returns the created ISqlQuery.
  • DeleteQuery (ISqlQuery query) Deletes the specified ISqlQuery from this connection.
  • NewScript (string name) -> ISqlScript Creates a new SQL script (file-based or inline, depending on script configuration) with the specified display name. Returns the created ISqlScript.
  • DeleteScript (ISqlScript script) Deletes the specified ISqlScript from this connection.

Properties

  • Name (string) {get}{set} Gets or sets the display name of the custom connection.
  • Type (string) {get}{set} Gets or sets the connection type (e.g., ODBC, OLE DB, provider-specific).
  • ConnectionString (string) {get}{set} Gets or sets the connection string used at install time to connect to the target database/server.
  • Condition (string) {get}{set} Gets or sets a Windows Installer condition. When the condition evaluates to false, the connection and its operations are skipped.
  • CreateDatabaseIfNotExists (bool) {get}{set} When true, attempts to create the database if it does not already exist.
  • Use64bitOdbcResource (bool) {get}{set} When true, uses 64-bit ODBC resources; when false, uses 32-bit.
  • LoginTimeout (uint) {get}{set} Gets or sets the login timeout (in seconds) for establishing the connection.
  • IsVerbose (bool) {get}{set} Enables verbose output for this connection’s operations when true.
  • LogErrorsToFile (bool) {get}{set} When true, logs errors to a file (location determined by project/logging settings).
  • Queries (SAFEARRAY(Variant)) {get} Returns an array of ISqlQuery objects defined under this connection.
  • Scripts (SAFEARRAY(Variant)) {get} Returns an array of ISqlScript objects defined under this connection.
  • Object (uint) {get} Read-only internal identifier for this connection instance.

Sample commands

# ISqlCustomConnection usage

$advinst  = New-Object -ComObject "AdvancedInstaller"
$project  = $advinst.CreateProject($advinst.ProjectTypes.Enterprise)

# Create a custom connection
$customConn = $project.SqlDatabasesComponent.NewCustomConnection("My Custom Connection")

# Set properties
$customConn.Type = "ODBC"     
$customConn.ConnectionString = "Driver={ODBC Driver 17 for SQL Server};Server=sql01;Database=Demo;Trusted_Connection=Yes;"
$customConn.CreateDatabaseIfNotExists = $true
$customConn.LoginTimeout = 30
$customConn.IsVerbose = $true
$customConn.LogErrorsToFile = $true
$customConn.Use64bitOdbcResource = $true

# Add a query
$query = $customConn.NewQuery("Create Table Demo")
$query.InlineScript = "CREATE TABLE Demo (Id INT PRIMARY KEY, Name NVARCHAR(100));"

# Add a script
$script = $customConn.NewScript("Seed Data Script")
$script.ScriptFile = "F:\cmdlet\res\seed.sql"

# Delete operations (optional cleanup)
# $customConn.DeleteQuery($query)
# $customConn.DeleteScript($script)

# Remove the connection entirely
# $project.SqlDatabasesComponent.DeleteDatabaseObject($customConn)

$project.SaveAs("F:\cmdlet\output\DemoProject Enterprise - CustomConnection.aip")