Permalink
Browse files

Merge pull request #4947 from nvarscar/appintent

ApplicationIntent fixes
  • Loading branch information...
potatoqualitee committed Jan 11, 2019
2 parents a31bb64 + c3c94fd commit fbad96f2643cb1c94179d8dca3eaee9c38bc3730
Showing with 11 additions and 5 deletions.
  1. +3 −3 functions/Connect-DbaInstance.ps1
  2. +8 −2 functions/Invoke-DbaQuery.ps1
@@ -352,6 +352,9 @@ function Connect-DbaInstance {
if (Test-Bound -ParameterName 'WorkstationId') {
$server.ConnectionContext.WorkstationId = $WorkstationId
}
if (Test-Bound -ParameterName 'ApplicationIntent') {
$server.ConnectionContext.ApplicationIntent = $ApplicationIntent
}

$connstring = $server.ConnectionContext.ConnectionString
if (Test-Bound -ParameterName 'MultiSubnetFailover') {
@@ -360,9 +363,6 @@ function Connect-DbaInstance {
if (Test-Bound -ParameterName 'FailoverPartner') {
$connstring = "$connstring;Failover Partner=$FailoverPartner"
}
if (Test-Bound -ParameterName 'ApplicationIntent') {
$connstring = "$connstring;ApplicationIntent=$ApplicationIntent"
}

if ($connstring -ne $server.ConnectionContext.ConnectionString) {
$server.ConnectionContext.ConnectionString = $connstring
@@ -297,8 +297,14 @@ function Invoke-DbaQuery {
}
foreach ($instance in $SqlInstance) {
try {
$intent = if ($ReadOnly) { "ReadOnly" } else { "ReadWrite" }
$server = Connect-DbaInstance -SqlInstance $instance -SqlCredential $SqlCredential -ApplicationIntent $intent
$connDbaInstanceParams = @{
SqlInstance = $instance
SqlCredential = $SqlCredential
}
if ($ReadOnly) {
$connDbaInstanceParams.ApplicationIntent = "ReadOnly"
}
$server = Connect-DbaInstance @connDbaInstanceParams
} catch {
Stop-Function -Message "Failure" -ErrorRecord $_ -Target $instance -Continue
}

0 comments on commit fbad96f

Please sign in to comment.