This project is read-only.

Synopsis

Open a connection to a database server.

Syntax

Open-SqlConnection -ConnectionString <String> [-CommandTimeOut <Int32>] [-ConnectionName <String>] [<CommonParameters>]

Open-SqlConnection -ConnectionString <String> [-Oracle] [-CommandTimeOut <Int32>] [-ConnectionName <String>] [<CommonParameters>]

Open-SqlConnection -ConnectionString <String> [-SQLite] [-CommandTimeOut <Int32>] [-ConnectionName <String>] [<CommonParameters>]

Open-SqlConnection -ConnectionString <String> [-PostGre] [-CommandTimeOut <Int32>] [-ConnectionName <String>] [<CommonParameters>]

Open-SqlConnection [-IWA] [[-DataSource] <String>] [[-InitialCatalog] <String>] [-CommandTimeOut <Int32>] [-ConnectionName <String>] [<CommonParameters>]

Open-SqlConnection -Oracle <SwitchParameter> [-DataSource] <String> [-ServiceName] <String> [[-Port] <Int32>] [-User] <String> [-Password] <String> [-CommandTimeOut <Int32>] [-ConnectionName <String>] [<CommonParameters>]

Open-SqlConnection -PostGre <SwitchParameter> [-DataSource] <String> [[-InitialCatalog] <String>] [[-Port] <Int32>] [-User] <String> [-Password] <String> [-CommandTimeOut <Int32>] [-ConnectionName <String>] [<CommonParameters>]

Open-SqlConnection -SQLite <SwitchParameter> [[-DataSource] <String>] [[-Password] <String>] [-CommandTimeOut <Int32>] [-ConnectionName <String>] [<CommonParameters>]

Open-SqlConnection [-DataSource] <String> [[-InitialCatalog] <String>] [-User] <String> [-Password] <String> [-CommandTimeOut <Int32>] [-ConnectionName <String>] [<CommonParameters>]

Description

Open a connection to a database server. Supports SQL Server, SQLite, Oracle (10.2+), and PostGreSql.

Parameters

-CommandTimeOut <Int32>

The default command timeout to be used for all commands executed against this sql connection.

Required? False
Position? named
Default value 30
Accept pipeline input? false
Accept wildcard characters? False

-ConnectionName <String>

User defined name for connection.

Required? False
Position? named
Default value Default
Accept pipeline input? false
Accept wildcard characters? False

-ConnectionString <String>

Connection string for the sql connection.

Required? True
Position? named
Default value  
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? False

-Oracle <SwitchParameter>

Indicates this is an Oracle connection.

Required? False
Position? named
Default value  
Accept pipeline input? false
Accept wildcard characters? False

-SQLite <SwitchParameter>

Indicates this is a SQLite connection.

Required? False
Position? named
Default value  
Accept pipeline input? false
Accept wildcard characters? False

-PostGre <SwitchParameter>

Indicates this is a PostGre connection.

Required? False
Position? named
Default value  
Accept pipeline input? false
Accept wildcard characters? False

-IWA <SwitchParameter>

Indicates this is a MSSQL connection using Integrated Authentication.

Required? False
Position? named
Default value  
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? False

-DataSource <String>

The datasource for the connection. For MSSQL connections, defaults to "localhost"; for SQLite connections, defaults to ":memory:"; all other connections it is mandatory.
MSSQL: Instance Name
Oracle: host
PostGre: Host
SQLite: file path

Required? False
Position? 1
Default value localhost
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? False

-InitialCatalog <String>

Database catalog to connect to. This is not applicable for Oracle or SQLite connections.
MSSQL: Master
PostGre will require you to pass in a value.

Required? False
Position? 2
Default value master
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? False

-Port <Int32>

Sql Connection port, this is only applicable to PostGre (5432) and Oracle (1521).

Required? False
Position? 2
Default value 5432 or 1521
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? False

-ServiceName <String>

Oracle only, the Oracle ServiceName (SID)

Required? True
Position? 3
Default value  
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? False

-User <String>

User name to authenticate with.

Required? True
Position? 4
Default value  
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? False

-Password <String>

Password to authenticate with.

Required? True
Position? 5
Default value  
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? False

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

Examples

Example 1

PS C:\> Open-SqlConnection

Opens a MSSQL connection to ‘localhost’ database &;39;master&;39; using Integrated Authentication.

Example 2

PS C:\> Open-SqlConnection -Database test -ConnectionName TestConn

Opens a MSSQL connection to ‘localhost’ database ‘test’ using Integrated Authentication and names the connection "TestConn"

Example 3

PS C:\> Open-SqlConnection -SQLite

Opens a SQLite connection to an in-memory database.

Example 4

PS C:\> Open-SqlConnection -SQLite -Datasource "c:\somedir\someFile.db"

Opens a SQLite connection to the file "c:\somedir\someFile.db", will create the file if it doesn’t exist, otherwise open it if it does exist.

Example 5

PS C:\> Open-SqlConnection -Oracle -DataSource someServer -Port 1551 -ServiceName myOraSid -User test -Password mySecret

Opens an oracle connection to the ‘myOraSid’ hosted on someServer:1551 with user ‘test’ and password ‘mySecret’.

Example 6

PS C:\> Open-SqlConnection -PostGre -DataSource someServer -InitalCatalog MyDb -User test -Password mySecret

Opens a PostGre connection to the database ‘MyDb’ hosted on someServer:5432 (default port) with user ‘test’ and password ‘mySecret’.

Last edited Jun 23, 2015 at 2:29 PM by mastertook, version 3