Skip to content

Instantly share code, notes, and snippets.

@Packet-Lost
Created August 26, 2017 23:46
Show Gist options
  • Save Packet-Lost/cbb8d791fa6042519339b672bd2b844d to your computer and use it in GitHub Desktop.
Save Packet-Lost/cbb8d791fa6042519339b672bd2b844d to your computer and use it in GitHub Desktop.
Test AlwaysOn Application Read Intent Routing with PowerShell
##replace variables as needed##
$Server = 'AvailabilityGroupListener.fqdn.com'
$Database = 'DatabaseInsideAvailabilityGroup'
$Connection = New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionString = "Server=$($Server);Database=$($Database);Integrated Security=True;MultiSubnetFailover=True"
$Connection.Open()
$Command = New-Object System.Data.SQLClient.SQLCommand
$Command.Connection = $Connection
$Command.CommandText = 'Select @@SERVERNAME'
$Reader = $Command.ExecuteReader()
$Datatable = New-Object System.Data.DataTable
$Datatable.Load($Reader)
$Datatable
$Connection.Close()
$Connection = New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionString = "Server=$($Server);Database=$($database);Integrated Security=True;MultiSubnetFailover=True;ApplicationIntent=ReadOnly"
$Connection.Open()
$Command = New-Object System.Data.SQLClient.SQLCommand
$Command.Connection = $Connection
$Command.CommandText = 'Select @@SERVERNAME'
$Reader = $Command.ExecuteReader()
$Datatable = New-Object System.Data.DataTable
$Datatable.Load($Reader)
$Datatable
$Connection.Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment