Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion AdvancedConnectivityPolicyTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ $EncryptionProtocol = $parameters['EncryptionProtocol']
$RepositoryBranch = $parameters['RepositoryBranch']
$Local = $parameters['Local']
$LocalPath = $parameters['LocalPath']
$TrustServerCertificate = $parameters['TrustServerCertificate']
$EncryptionOption = $parameters['EncryptionOption']



if ([string]::IsNullOrEmpty($env:TEMP)) {
Expand All @@ -153,6 +156,7 @@ try {
else {
$path = $env:TEMP + "/AzureSQLConnectivityChecker/TDSClient.dll"
Invoke-WebRequest -Uri $('https://github.com/Azure/SQL-Connectivity-Checker/raw/' + $RepositoryBranch + '/netstandard2.0/TDSClient.dll') -OutFile $path -UseBasicParsing

}

$path = $env:TEMP + "/AzureSQLConnectivityChecker/TDSClient.dll"
Expand Down Expand Up @@ -185,7 +189,7 @@ try {
$encryption = [System.Security.Authentication.SslProtocols]::Tls12 -bor [System.Security.Authentication.SslProtocols]::Tls11 -bor [System.Security.Authentication.SslProtocols]::Default
}
}
$tdsClient = [TDSClient.TDS.Client.TDSSQLTestClient]::new($Server, $Port, $User, $Password, $Database, $encryption)
$tdsClient = [TDSClient.TDS.Client.TDSSQLTestClient]::new($Server, $Port, $User, $Password, $Database, $TrustServerCertificate, $EncryptionOption, $encryption)
$tdsClient.Connect()
$tdsClient.Disconnect()
}
Expand Down
121 changes: 100 additions & 21 deletions AzureSQLConnectivityChecker.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ if ($null -ne $parameters) {
if ($null -ne $parameters['RepositoryBranch']) {
$RepositoryBranch = $parameters['RepositoryBranch']
}
if($null -ne $parameters['TrustServerCertificate']){
$TrustServerCertificate = $parameters['TrustServerCertificate']
}
write-host $TrustServerCertificate
if($null -ne $parameters['EncryptionOption']){
$EncryptionOption = $parameters['EncryptionOption']
}
write-host $EncryptionOption
}

$Server = $Server.Trim()
Expand All @@ -65,6 +73,8 @@ $Server = $Server.Replace(',1433', '')
$Server = $Server.Replace(',3342', '')
$Server = $Server.Replace(';', '')

$flag = $false

if ($null -eq $User -or '' -eq $User) {
$User = 'AzSQLConnCheckerUser'
}
Expand Down Expand Up @@ -224,7 +234,50 @@ function PrintDNSResults($dnsResult, [string] $dnsSource) {
}
}

function ValidateDNS([String] $Server) {
function ValidateDnsHelper([string] $Server1){
$flag = ValidateDNS $Server
if($flag -eq $false){
$flag = ValidateDNS ($Server1 + '.database.windows.net')
if($flag -eq $true){
$Server1 = ($Server + '.database.windows.net')
}
}
if($flag -eq $false){
$flag = ValidateDNS $Server1 + '.database.cloudapi.de'
if($flag -eq $true){
$Server1 = ($Server + '.database.cloudapi.de')
}
}
if($flag -eq $false){
$flag = ValidateDNS ($Server1 + '.database.chinacloudapi.cn')
if($flag -eq $true){
$Server1 = ($Server + '.database.chinacloudapi.cn')
}
}
if($flag -eq $false){
$flag = ValidateDNS ($Server1 + '.database.usgovcloudapi.net')
if($flag -eq $true){
$Server1 = ($Server + '.database.usgovcloudapi.net')
}
}
if($flag -eq $false){
$flag = ValidateDNS ($Server1 + '.sql.azuresynapse.net')
if($flag -eq $true){
$Server1 = ($Server + '.sql.azuresynapse.net')
}
}
if($flag -eq $true){
$Server = $Server1
Write-Host $Server
return [bool]($flag), $Server1
}else{
Write-Host "Error at ValidateDNS" -Foreground Red
Write-Host "Server cant be Validated" -Foreground Red
$host.exit()
}
}

function ValidateDNS([string] $Server) {
Try {
Write-Host 'Validating DNS record for' $Server -ForegroundColor Green

Expand All @@ -239,13 +292,23 @@ function ValidateDNS([String] $Server) {

$DNSfromAzureDNS = Resolve-DnsName -Name $Server -DnsOnly -Server 208.67.222.222 -ErrorAction SilentlyContinue
PrintDNSResults $DNSfromAzureDNS 'Open DNS'

return [bool]($DNSfromAzureDNS -or $DNSfromCache -or $DNSfromCustomerServer -or $DNSfromHosts)
}
Catch {
Write-Host "Error at ValidateDNS" -Foreground Red
Write-Host $_.Exception.Message -ForegroundColor Red
}
}

function CheckIfIpAddress([string] $Server){
if($Server -match "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"){
return $true
}else{
return $false
}
}

function IsManagedInstance([String] $Server) {
return [bool]((($Server.ToCharArray() | Where-Object { $_ -eq '.' } | Measure-Object).Count) -ge 4)
}
Expand Down Expand Up @@ -476,7 +539,7 @@ function RunSqlDBConnectivityTests($resolvedAddress) {
}

$gateway = $SQLDBGateways | Where-Object { $_.Gateways -eq $resolvedAddress }
if (!$gateway) {
if (!$gateway -and !($resolvedAddress -eq '127.0.0.1') -and !($resolvedAddress -eq '::1')) {
Write-Host ' ERROR:' $resolvedAddress 'is not a valid gateway address' -ForegroundColor Red
Write-Host ' Please review your DNS configuration, it should resolve to a valid gateway address' -ForegroundColor Red
Write-Host ' See the valid gateway addresses at https://docs.microsoft.com/en-us/azure/sql-database/sql-database-connectivity-architecture#azure-sql-database-gateway-ip-addresses' -ForegroundColor Red
Expand Down Expand Up @@ -574,6 +637,8 @@ function RunConnectivityPolicyTests($port) {
RepositoryBranch = $RepositoryBranch
Local = $Local
LocalPath = $LocalPath
TrustServerCertificate = $TrustServerCertificate
EncryptionOption = $EncryptionOption
}

if (Test-Path "$env:TEMP\AzureSQLConnectivityChecker\") {
Expand All @@ -584,6 +649,7 @@ function RunConnectivityPolicyTests($port) {

if ($Local) {
Copy-Item -Path $($LocalPath + './AdvancedConnectivityPolicyTests.ps1') -Destination "$env:TEMP\AzureSQLConnectivityChecker\AdvancedConnectivityPolicyTests.ps1"

}
else {
Invoke-WebRequest -Uri $('https://raw.githubusercontent.com/Azure/SQL-Connectivity-Checker/' + $RepositoryBranch + '/AdvancedConnectivityPolicyTests.ps1') -OutFile "$env:TEMP\AzureSQLConnectivityChecker\AdvancedConnectivityPolicyTests.ps1" -UseBasicParsing
Expand Down Expand Up @@ -694,13 +760,13 @@ try {
throw
}

if (!$Server.EndsWith('.database.windows.net') `
-and !$Server.EndsWith('.database.cloudapi.de') `
-and !$Server.EndsWith('.database.chinacloudapi.cn') `
-and !$Server.EndsWith('.database.usgovcloudapi.net') `
-and !$Server.EndsWith('.sql.azuresynapse.net')) {
$Server = $Server + '.database.windows.net'
}
#if (!$Server.EndsWith('.database.windows.net') `
# -and !$Server.EndsWith('.database.cloudapi.de') `
# -and !$Server.EndsWith('.database.chinacloudapi.cn') `
# -and !$Server.EndsWith('.database.usgovcloudapi.net') `
# -and !$Server.EndsWith('.sql.azuresynapse.net')) {
# $Server = $Server + '.database.windows.net'
#}

#Print local network configuration
PrintLocalNetworkConfiguration
Expand All @@ -718,20 +784,33 @@ try {
}
}

ValidateDNS $Server
$checkIP = CheckIfIpAddress $Server

try {
$dnsResult = [System.Net.DNS]::GetHostEntry($Server)
}
catch {
Write-Host ' ERROR: Name resolution of' $Server 'failed' -ForegroundColor Red
Write-Host ' Please make sure the server name FQDN is correct and that your machine can resolve it.' -ForegroundColor Red
Write-Host ' Failure to resolve domain name for your logical server is almost always the result of specifying an invalid/misspelled server name,' -ForegroundColor Red
Write-Host ' or a client-side networking issue that you will need to pursue with your local network administrator.' -ForegroundColor Red
Write-Error '' -ErrorAction Stop
if($checkIP -eq $false){
$return = ValidateDnsHelper $Server
$Server = $return[1]
$success = $return[0]


try {
$dnsResult = [System.Net.DNS]::GetHostEntry($Server)
}

catch {
Write-Host ' ERROR: Name resolution of' $Server 'failed' -ForegroundColor Red
Write-Host ' Please make sure the server name FQDN is correct and that your machine can resolve it.' -ForegroundColor Red
Write-Host ' Failure to resolve domain name for your logical server is almost always the result of specifying an invalid/misspelled server name,' -ForegroundColor Red
Write-Host ' or a client-side networking issue that you will need to pursue with your local network administrator.' -ForegroundColor Red
Write-Error '' -ErrorAction Stop
}
$resolvedAddress = $dnsResult.AddressList[0].IPAddressToString
$dbPort = 1433
$resolvedAddress = $dnsResult.AddressList[0].IPAddressToString
$dbPort = 1433
}else{
$resolvedAddress = $Server
$dbPort = 1433
}

write-host $resolvedAddress

#Run connectivity tests
Write-Host
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ $parameters = @{
# Supports Single, Elastic Pools and Managed Instance (please provide FQDN, MI public endpoint is supported)
# Supports Azure Synapse / Azure SQL Data Warehouse (*.sql.azuresynapse.net / *.database.windows.net)
# Supports Public Cloud (*.database.windows.net), Azure China (*.database.chinacloudapi.cn), Azure Germany (*.database.cloudapi.de) and Azure Government (*.database.usgovcloudapi.net)
Server = '.database.windows.net' # or any other supported FQDN
Database = '' # Set the name of the database you wish to test, 'master' will be used by default if nothing is set
User = '' # Set the login username you wish to use, 'AzSQLConnCheckerUser' will be used by default if nothing is set
Password = '' # Set the login password you wish to use, 'AzSQLConnCheckerPassword' will be used by default if nothing is set
Server = 'localhost' # or any other supported FQDN
Database = 'master' # Set the name of the database you wish to test, 'master' will be used by default if nothing is set
User = 'admin' # Set the login username you wish to use, 'AzSQLConnCheckerUser' will be used by default if nothing is set
Password = 'admin' # Set the login password you wish to use, 'AzSQLConnCheckerPassword' will be used by default if nothing is set
TrustServerCertificate = '' #Boolean value, 'true' will be used by default if nothing is set
EncryptionOption = '' # TDS Encryption option sent by the client, can be: 'EncryptOn', 'EncryptOff', 'EncryptNotSup', 'EncryptReq', 'EncryptClientCertOff', 'EncryptClientCertOn', 'EncryptClientCertReq', 'EncryptOn' will be used by default if nothing is set

## Optional parameters (default values will be used if omitted)
SendAnonymousUsageData = $true # Set as $true (default) or $false
RunAdvancedConnectivityPolicyTests = $true # Set as $true (default) or $false, this will load the library from Microsoft's GitHub repository needed for running advanced connectivity tests
RunAdvancedConnectivityPolicyTests = $false # Set as $true (default) or $false, this will load the library from Microsoft's GitHub repository needed for running advanced connectivity tests
CollectNetworkTrace = $true # Set as $true (default) or $false
#EncryptionProtocol = '' # Supported values: 'Tls 1.0', 'Tls 1.1', 'Tls 1.2'; Without this parameter operating system will choose the best protocol to use
}
Expand Down
26 changes: 18 additions & 8 deletions ReducedSQLConnectivityChecker.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ if ($null -ne $parameters) {
if ($null -ne $parameters['RepositoryBranch']) {
$RepositoryBranch = $parameters['RepositoryBranch']
}
$TrustServerCertificate = $parameters['TrustServerCertificate']
$EncryptionOption = $parameters['EncryptionOption']
}

$Server = $Server.Trim()
Expand All @@ -35,6 +37,14 @@ if ($null -eq $Local) {

if ($null -eq $RepositoryBranch) {
$RepositoryBranch = 'master'
}

if ($null -eq $TrustServerCertificate -or '' -eq $TrustServerCertificate){
$TrustServerCertificate = $true
}

if ($null -eq $EncryptionOption -or '' -eq $EncryptionOption){
$EncryptionOption = 'EncryptOn'
}

# PowerShell Container Image Support Start
Expand Down Expand Up @@ -223,13 +233,13 @@ try {
throw
}

if (!$Server.EndsWith('.database.windows.net') `
-and !$Server.EndsWith('.database.cloudapi.de') `
-and !$Server.EndsWith('.database.chinacloudapi.cn') `
-and !$Server.EndsWith('.sql.azuresynapse.net')) {
$Server = $Server + '.database.windows.net'
}

# if (!$Server.EndsWith('.database.windows.net') `
# -and !$Server.EndsWith('.database.cloudapi.de') `
# -and !$Server.EndsWith('.database.chinacloudapi.cn') `
# -and !$Server.EndsWith('.sql.azuresynapse.net')) {
# $Server = $Server + '.database.windows.net'
# }
if ($SendAnonymousUsageData) {
SendAnonymousUsageData
}
Expand Down Expand Up @@ -281,7 +291,7 @@ try {
$Port = 3342
}

$tdsClient = [TDSClient.TDS.Client.TDSSQLTestClient]::new($Server, $Port, $User, $Password, $Database, $encryption)
$tdsClient = [TDSClient.TDS.Client.TDSSQLTestClient]::new($Server, $Port, $User, $Password, $Database, $encryption, $TrustServerCertificate, $EncryptionOption)
$tdsClient.Connect()
$tdsClient.Disconnect()
}
Expand Down
14 changes: 9 additions & 5 deletions RunLocally.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ $LocalPath = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definiti

# Script parameters
$parameters = @{
Server = '.database.windows.net'
Database = '' # Set the name of the database you wish to test, 'master' will be used by default if nothing is set
User = '' # Set the login username you wish to use, 'AzSQLConnCheckerUser' will be used by default if nothing is set
Password = '' # Set the login password you wish to use, 'AzSQLConnCheckerPassword' will be used by default if nothing is set
Server = 'localhost'
Database = 'master' # Set the name of the database you wish to test, 'master' will be used by default if nothing is set
User = 'admin' # Set the login username you wish to use, 'AzSQLConnCheckerUser' will be used by default if nothing is set
Password = 'admin' # Set the login password you wish to use, 'AzSQLConnCheckerPassword' will be used by default if nothing is set
TrustServerCertificate = 'true' #Boolean value, 'true' will be used by default if nothing is set
EncryptionOption = 'EncryptNotSup' # TDS Encryption option sent by the client, can be: 'EncryptOn', 'EncryptOff', 'EncryptNotSup', 'EncryptReq', 'EncryptClientCertOff', 'EncryptClientCertOn', 'EncryptClientCertReq', 'EncryptOn' will be used by default if nothing is set



## Optional parameters (default values will be used if ommited)
SendAnonymousUsageData = $true # Set as $true (default) or $false
RunAdvancedConnectivityPolicyTests = $true # Set as $true (default) or $false, this will download the library needed for running advanced connectivity tests
CollectNetworkTrace = $true # Set as $true (default) or $false
#EncryptionProtocol = '' # Supported values: 'Tls 1.0', 'Tls 1.1', 'Tls 1.2'; Without this parameter operating system will choose the best protocol to use
EncryptionProtocol = 'Tls 1.2' # Supported values: 'Tls 1.0', 'Tls 1.1', 'Tls 1.2'; Without this parameter operating system will choose the best protocol to use

## Run locally parameters
Local = $true # Do Not Change
Expand Down
2 changes: 1 addition & 1 deletion TDSClient/TDSClient.UnitTests/TDSClient.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion TDSClient/TDSClient/TDS/Client/TDSClientVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ public bool Equals(TDSClientVersion other)
this.SubBuildNumber == other.SubBuildNumber;
}
}
}
}
Loading