Sunday, June 14, 2015

Powershell Connection string to an instance of SQL Server 2012 on local computer

We are assuming a named instance 'RegencyPark' on a laptop machine named 'Hodentek8'. The Connection string used for connecting to this instance using PowerShell is in the string variable $ConnectionString:


Windows PowerShell ISE provides intellisense support and for the Connection provides the following drop-down:

You can use the following statements to connect to the instance and open the connection (Properties and Methods):

$Connection = New-Object System.Data.SQLClient.SQLConnection($ConnectionString)

The last statement when executed displays 'Open'

You can further looks at the properties of the connection string as shown here:
PS C:\Users\Jayaram>

PS C:\Users\Jayaram>  $Connection = New-Object System.Data.SQLClient.SQLConnection($ConnectionString)

PS C:\Users\Jayaram>  $Connection.Open()

PS C:\Users\Jayaram>  $Connection.State

PS C:\Users\Jayaram>  $Connection.Database

PS C:\Users\Jayaram>  $Connection.Credential

PS C:\Users\Jayaram>  $Connection.DataSource

PS C:\Users\Jayaram>  $Connection.ConnectionTimeout

PowerShell Pro Tools is a Visual Studio Community 2017 extension that you can try free

I see there is at least one extension, PowerShell Pro Tools that you can download. You can find it in the Visual Studio Community 2017...