Created
August 26, 2017 23:46
-
-
Save Packet-Lost/cbb8d791fa6042519339b672bd2b844d to your computer and use it in GitHub Desktop.
Test AlwaysOn Application Read Intent Routing with PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##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