Skip to content

Commit

Permalink
A few more azure fixes (#5185)
Browse files Browse the repository at this point in the history
* more azure fixes

* return azure connstring

* add new db support for azure

* remove open requirement
  • Loading branch information
potatoqualitee authored Mar 11, 2019
1 parent 992c798 commit 2bc61a6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
3 changes: 0 additions & 3 deletions functions/Connect-DbaInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ function Connect-DbaInstance {

# Gracefully handle Azure connections
if ($instance.ComputerName -match "database\.windows\.net" -and -not $instance.InputObject.ConnectionContext.IsOpen) {
if (-not $Database) {
Stop-Function -Message "You must specify -Database when connecting to a SQL Azure databse" -Continue
}
$isAzure = $true

# Use available command to build the proper connection string
Expand Down
32 changes: 20 additions & 12 deletions functions/New-DbaConnectionString.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,30 @@ function New-DbaConnectionString {
process {
foreach ($instance in $sqlinstance) {
if ($Pscmdlet.ShouldProcess($instance, "Making a new Connection String")) {
if ($instance.ComputerName -match "database\.windows\.net" -and -not $instance.InputObject.ConnectionContext.IsOpen) {
if (-not $Database) {
Stop-Function -Message "You must specify -Database when connecting to a SQL Azure databse" -Continue
}
$isAzure = $true
if ($instance.ComputerName -match "database\.windows\.net") {
if ($instance.InputObject.GetType() -eq [Microsoft.SqlServer.Management.Smo.Server]) {
$connstring = $instance.InputObject.ConnectionContext.ConnectionString
if ($Database) {
$olddb = $connstring -split ';' | Where { $_.StartsWith("Initial Catalog")}
$newdb = "Initial Catalog=$Database"
$connstring = $connstring.Replace($olddb, $newdb)
}
$connstring
continue
} else {
$isAzure = $true

if (-not (Test-Bound -ParameterName ConnectTimeout)) {
$ConnectTimeout = 30
}
if (-not (Test-Bound -ParameterName ConnectTimeout)) {
$ConnectTimeout = 30
}

if (-not (Test-Bound -ParameterName ClientName)) {
$ClientName = "dbatools PowerShell module - dbatools.io"
if (-not (Test-Bound -ParameterName ClientName)) {
$ClientName = "dbatools PowerShell module - dbatools.io"

}
$EncryptConnection = $true
$instance = [DbaInstanceParameter]"tcp:$($instance.ComputerName),$($instance.Port)"
}
$EncryptConnection = $true
$instance = [DbaInstanceParameter]"tcp:$($instance.ComputerName),$($instance.Port)"
}

if ($instance.GetType() -eq [Microsoft.SqlServer.Management.Smo.Server]) {
Expand Down

0 comments on commit 2bc61a6

Please sign in to comment.