Skip to content

Commit 119ce8f

Browse files
author
Ajay Kumar Yadav
authored
Users/ajya/sql server module import m146 (#9360)
* Importing Sqlserver module * updated task.json
1 parent 741d787 commit 119ce8f

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

Tasks/SqlAzureDacpacDeploymentV1/SqlAzureActions.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,12 @@ function Run-SqlCmd {
270270
}
271271
}
272272
elseif ($authenticationType -eq "connectionString") {
273+
Check-ConnectionString
273274
$commandToRun = "Invoke-Sqlcmd -connectionString `"$connectionString`" "
274275
$commandToLog = "Invoke-Sqlcmd -connectionString `"**********`" "
275276
}
276277
elseif ($authenticationType -eq "aadAuthenticationPassword" -or $authenticationType -eq "aadAuthenticationIntegrated") {
278+
Check-connectionString
277279
$connectionString = Get-AADAuthenticationConnectionString -authenticationType $authenticationType -serverName $serverName -databaseName $databaseName -sqlUserName $sqlUserName -sqlPassword $sqlPassword
278280
$commandToRun = "Invoke-Sqlcmd -connectionString `"$connectionString`" "
279281
$commandToLog = "Invoke-Sqlcmd -connectionString `"$connectionString`" "
@@ -286,6 +288,14 @@ function Run-SqlCmd {
286288
Invoke-Expression $commandToRun
287289
}
288290

291+
function Check-ConnectionString
292+
{
293+
if(-not (CmdletHasMember -cmdlet Invoke-SQlCmd -memberName "connectionString"))
294+
{
295+
throw (Get-VstsLocString -Key "SAD_InvokeSQLCmdNotSupportingConnectionString")
296+
}
297+
}
298+
289299
function Get-AgentIPRange
290300
{
291301
param(

Tasks/SqlAzureDacpacDeploymentV1/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,6 @@
7676
"loc.messages.SAD_DacpacFilePath": "DACPAC file path:",
7777
"loc.messages.SAD_BacpacFilePath": "BACPAC file path:",
7878
"loc.messages.SAD_PublishProfilePath": "Publish profile path:",
79-
"loc.messages.SAD_DriftReportWarning": "While generating a Drift Report of the database, ensure that the database is registered as a Data-tier Application."
79+
"loc.messages.SAD_DriftReportWarning": "While generating a Drift Report of the database, ensure that the database is registered as a Data-tier Application.",
80+
"loc.messages.SAD_InvokeSQLCmdNotSupportingConnectionString": "Imported Invoke-Sqlcmd doesn't support connectionString. Install SQLServer PS module."
8081
}

Tasks/SqlAzureDacpacDeploymentV1/Utility.ps1

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,33 @@ function EscapeSpecialChars
332332
# Function to import SqlPS module & avoid directory switch
333333
function Import-Sqlps {
334334
Push-Location
335-
Import-Module SqlPS -ErrorAction 'SilentlyContinue' 3>&1 | Out-Null
335+
336+
$modules = Get-Module -Name SQLServer -ListAvailable
337+
if ($modules)
338+
{
339+
Import-Module SQLServer -ErrorAction 'SilentlyContinue' 3>&1 | Out-Null
340+
Write-Verbose "Imported SQLServer PS module."
341+
} else {
342+
Write-Verbose "SQLServer PS module is not installed. Importing SQLPS"
343+
Import-Module SqlPS -ErrorAction 'SilentlyContinue' 3>&1 | Out-Null
344+
}
345+
336346
Pop-Location
337347
}
348+
349+
function CmdletHasMember {
350+
[CmdletBinding()]
351+
param(
352+
[Parameter(Mandatory=$true)]
353+
[string]$cmdlet,
354+
[Parameter(Mandatory=$true)]
355+
[string]$memberName)
356+
try{
357+
$hasMember = (gcm $cmdlet).Parameters.Keys.Contains($memberName)
358+
return $hasMember
359+
}
360+
catch
361+
{
362+
return $false;
363+
}
364+
}

Tasks/SqlAzureDacpacDeploymentV1/task.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"name": "SqlAzureDacpacDeployment",
44
"friendlyName": "Azure SQL Database Deployment",
55
"description": "Deploy Azure SQL DB using DACPAC or run scripts using SQLCMD",
6+
"helpUrl": "https://aka.ms/sqlazuredeployreadme",
67
"helpMarkDown": "[More Information](https://aka.ms/sqlazuredeployreadme)",
78
"category": "Deploy",
89
"visibility": [
@@ -16,7 +17,7 @@
1617
"version": {
1718
"Major": 1,
1819
"Minor": 3,
19-
"Patch": 11
20+
"Patch": 12
2021
},
2122
"demands": [
2223
"sqlpackage"
@@ -362,6 +363,7 @@
362363
"SAD_DacpacFilePath": "DACPAC file path:",
363364
"SAD_BacpacFilePath": "BACPAC file path:",
364365
"SAD_PublishProfilePath": "Publish profile path:",
365-
"SAD_DriftReportWarning": "While generating a Drift Report of the database, ensure that the database is registered as a Data-tier Application."
366+
"SAD_DriftReportWarning": "While generating a Drift Report of the database, ensure that the database is registered as a Data-tier Application.",
367+
"SAD_InvokeSQLCmdNotSupportingConnectionString": "Imported Invoke-Sqlcmd doesn't support connectionString. Install SQLServer PS module."
366368
}
367369
}

Tasks/SqlAzureDacpacDeploymentV1/task.loc.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"name": "SqlAzureDacpacDeployment",
44
"friendlyName": "ms-resource:loc.friendlyName",
55
"description": "ms-resource:loc.description",
6+
"helpUrl": "https://aka.ms/sqlazuredeployreadme",
67
"helpMarkDown": "ms-resource:loc.helpMarkDown",
78
"category": "Deploy",
89
"visibility": [
@@ -16,7 +17,7 @@
1617
"version": {
1718
"Major": 1,
1819
"Minor": 3,
19-
"Patch": 11
20+
"Patch": 12
2021
},
2122
"demands": [
2223
"sqlpackage"
@@ -362,6 +363,7 @@
362363
"SAD_DacpacFilePath": "ms-resource:loc.messages.SAD_DacpacFilePath",
363364
"SAD_BacpacFilePath": "ms-resource:loc.messages.SAD_BacpacFilePath",
364365
"SAD_PublishProfilePath": "ms-resource:loc.messages.SAD_PublishProfilePath",
365-
"SAD_DriftReportWarning": "ms-resource:loc.messages.SAD_DriftReportWarning"
366+
"SAD_DriftReportWarning": "ms-resource:loc.messages.SAD_DriftReportWarning",
367+
"SAD_InvokeSQLCmdNotSupportingConnectionString": "ms-resource:loc.messages.SAD_InvokeSQLCmdNotSupportingConnectionString"
366368
}
367-
}
369+
}

0 commit comments

Comments
 (0)