Skip to content

Commit

Permalink
Changes to xSQLServerHelper
Browse files Browse the repository at this point in the history
Connect-SQLAnalysis now has correct error handling, and throw does not used the unknown namned parameter '-Message' (issue dsccommunity#436).
  • Loading branch information
johlju committed Mar 13, 2017
1 parent 7fe4544 commit 5802643
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions xSQLServerHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function Connect-SQLAnalysis

[ValidateNotNull()]
[System.String]
$SQLInstanceName = "MSSQLSERVER",
$SQLInstanceName = 'MSSQLSERVER',

[ValidateNotNull()]
[System.Management.Automation.PSCredential]
Expand All @@ -103,7 +103,7 @@ function Connect-SQLAnalysis

$null = [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.AnalysisServices')

if ($SQLInstanceName -eq "MSSQLSERVER")
if ($SQLInstanceName -eq 'MSSQLSERVER')
{
$connectSql = $SQLServer
}
Expand All @@ -112,28 +112,38 @@ function Connect-SQLAnalysis
$connectSql = "$SQLServer\$SQLInstanceName"
}

$sql = New-Object Microsoft.AnalysisServices.Server

if ($SetupCredential)
try
{
$userName = $SetupCredential.GetNetworkCredential().UserName
$password = $SetupCredential.GetNetworkCredential().Password
if ($SetupCredential)
{
$userName = $SetupCredential.GetNetworkCredential().UserName
$password = $SetupCredential.GetNetworkCredential().Password

$sql.Connect("Data Source=$connectSql;User ID=$userName;Password=$password")
}
else
{
$sql.Connect("Data Source=$connectSql")
}
$analysisServicesDataSource = "Data Source=$connectSql;User ID=$userName;Password=$password"
}
else
{
$analysisServicesDataSource = "Data Source=$connectSql"
}

if (!$sql)
$analysisServicesObject = New-Object Microsoft.AnalysisServices.Server
$analysisServicesObject.Connect($analysisServicesDataSource)

if (-not $analysisServicesObject)
{
throw "Connected to $connectSql, but something went wrong. Did not get a Analysis Services server object back."
}
else
{
Write-Verbose -Message "Connected to Analysis Services $connectSql."
}
}
catch
{
Throw -Message "Failed connecting to Analysis Services $connectSql"
throw "Failed to connect to Analysis Services $connectSql."
}

New-VerboseMessage -Message "Connected to Analysis Services $connectSql"

return $sql
return $analysisServicesObject
}

<#
Expand Down Expand Up @@ -1556,7 +1566,7 @@ function Remove-SqlDatabasePermission
.PARAMETER SQLServer
The hostname of the server that hosts the SQL instance.
.PARAMETER SQLInstanceName
The name of the SQL instance that hosts the database.
Expand Down

0 comments on commit 5802643

Please sign in to comment.