SQL Predefined Connection (ISqlPredefinedConnection)

Overview

The SQL Predefined Connection represents a connection to a database where most parameters (server, database name, driver, and authentication) are explicitly configured ahead of time.

Predefined connections support both Windows Authentication (trusted) and SQL Authentication (username/password), and can automatically create the database if it does not already exist. You can also configure the ODBC driver, data source, port, and logging options. At install time, Advanced Installer uses these settings to establish a connection and run any associated queries or scripts.

This object is created using SqlDatabasesComponent.NewPredefinedConnection and appears in the SQL Databases page in Advanced Installer.

Isqldatabasescomponent predefined connection

Methods

  • NewQuery (string name) → ISqlQuery Creates a new SQL query under this predefined 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 under this connection 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 predefined connection.
  • Type (string) {get}{set} Gets or sets the connection type (e.g., SQLServer).
  • ServerHostName (string) {get}{set} Gets or sets the server host name or instance (e.g., dbserver01 or dbserver01\SQLEXPRESS).
  • Port (string) {get}{set} Gets or sets the server port (e.g., 1433).
  • DatabaseName (string) {get}{set} Gets or sets the target database name.
  • Driver (string) {get}{set} Gets or sets the ODBC driver name used by the connection (e.g., ODBC Driver 17 for SQL Server).
  • DataSource (string) {get}{set} Gets or sets the data source value (DSN or provider-specific source name), if required by the driver.
  • Username (string) {get}{set} Gets or sets the username for SQL authentication.
  • Password (string) {get}{set} Gets or sets the password for SQL authentication. For security, prefer PasswordProperty.
  • PasswordProperty (string) {get}{set} Gets or sets the installer property that supplies the password at runtime (instead of storing it in clear text).
  • UseTrustedConnection (bool) {get}{set} When true, uses Windows Authentication.
  • CreateDatabaseIfNotExists (bool) {get}{set} When true, creates the database if it does not already exist.
  • Use64bitOdbcResource (bool) {get}{set} When true, uses 64-bit ODBC resources; otherwise, 32-bit.
  • LoginTimeout (uint) {get}{set} Gets or sets the login timeout in seconds.
  • Condition (string) {get}{set} Gets or sets an install condition. When false, the connection and its operations are skipped.
  • IsVerbose (bool) {get}{set} Enables verbose logging for this connection’s operations.
  • LogErrorsToFile (bool) {get}{set} When true, logs errors to a file (location determined by project/logging settings).
  • LocalDataSources (SAFEARRAY(string)) {get} Returns a list of available data sources (DSN) on the local machine.
  • LocalDrivers (SAFEARRAY(string)) {get} Returns a list of ODBC drivers available on the local machine.
  • 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

# ISqlPredefinedConnection usage

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

# Create a predefined connection
$predefConn = $project.SqlDatabasesComponent.NewPredefinedConnection("SQL Server Predefined Connection")

# Set connection type and driver
$predefConn.Type = "SQLServer"
$predefConn.Driver = "ODBC Driver 17 for SQL Server"
$predefConn.DataSource = "MSSQLServer"

$predefConn.Use64bitOdbcResource = $true

# Configure server and database
$predefConn.ServerHostName = "localhost"
$predefConn.Port = "1433"
$predefConn.DatabaseName = "DemoDb"
$predefConn.CreateDatabaseIfNotExists = $true

# Authentication: Trusted or Username/Password
$predefConn.UseTrustedConnection = $true
# Alternative:
# $predefConn.UseTrustedConnection = $false
# $predefConn.Username = "dbuser"
# $predefConn.PasswordProperty = "DB_PASSWORD"

# Other options
$predefConn.LoginTimeout = 30
$predefConn.IsVerbose = $true
$predefConn.LogErrorsToFile = $true

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

# List queries
$predefConn.Queries

# Delete query (optional)
# $predefConn.DeleteQuery($q)

# Remove the connection (optional cleanup)
# $project.SqlDatabasesComponent.DeleteDatabaseObject($predefConn)

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