From 89f640b5c593c6fecef17f2ffe93b2aa5e7811b9 Mon Sep 17 00:00:00 2001 From: Yochanan Rachamim Date: Wed, 20 Dec 2017 02:57:24 +0200 Subject: [PATCH 1/2] Variable for log file name uses variable for log file location instead of a hardcoded file name --- SQLConnectivityTest.ps1 | 49 ++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/SQLConnectivityTest.ps1 b/SQLConnectivityTest.ps1 index a0a9e87..c3ca287 100644 --- a/SQLConnectivityTest.ps1 +++ b/SQLConnectivityTest.ps1 @@ -1,10 +1,12 @@ -$DatabaseServer = "xxxxx.database.windows.net" -$Database = "xxxxxx" -$Username = "xxxxxx" -$Password = "xxxxxx" +$DatabaseServer = "yochanan.database.windows.net" +$Database = "AdventureWorks" +$Username = "yochanan" +$Password = "P@ssw0rd" $Pooling = $true $NumberExecutions =10 -$File = "E:\TSQL.SQL" +$WorkingDirectory = "C:\TEMP\" +$File = $WorkingDirectory + "TSQL.txt" +$LogFile = $WorkingDirectory + "MyLog.txt" cls @@ -51,28 +53,29 @@ cls $connection.Close() $end = get-date $data = $connection.RetrieveStatistics() - write-Output "-------------------------" | Out-File e:\my.log -Append -width 300 - write-Output ("Query : " + $query[$iQuery]) | Out-File e:\my.log -Append -width 300 - write-Output ("Iteration : " +$i) | Out-File e:\my.log -Append -Width 300 - write-Output ("Time required (ms) : " +(New-TimeSpan -Start $start -End $end).TotalMilliseconds) | Out-File e:\my.log -Append -Width 300 - write-Output ("NetworkServerTime (ms): " +$data.NetworkServerTime) | Out-File e:\my.log -Append -Width 300 - write-Output ("Execution Time (ms) : " +$data.ExecutionTime) | Out-File e:\my.log -Append -Width 300 - write-Output ("Connection Time : " +$data.ConnectionTime) | Out-File e:\my.log -Append -Width 300 - write-Output ("ServerRoundTrips : " +$data.ServerRoundtrips) | Out-File e:\my.log -Append -Width 300 - write-Output ("BuffersReceived : " +$data.BuffersReceived) | Out-File e:\my.log -Append -Width 300 - write-Output ("SelectRows : " +$data.SelectRows) | Out-File e:\my.log -Append -Width 300 - write-Output ("SelectCount : " +$data.SelectCount) | Out-File e:\my.log -Append -Width 300 - write-Output ("BytesSent : " +$data.BytesSent) | Out-File e:\my.log -Append -Width 300 - write-Output ("BytesReceived : " +$data.BytesReceived) | Out-File e:\my.log -Append -Width 300 - write-Output "-------------------------" | Out-File e:\my.log -Append -Width 300 + write-Output "-------------------------" | Out-File $LogFile -Append -width 300 + write-Output ("Query : " + $query[$iQuery]) | Out-File $LogFile -Append -width 300 + write-Output ("Iteration : " +$i) | Out-File $LogFile -Append -Width 300 + write-Output ("Time required (ms) : " +(New-TimeSpan -Start $start -End $end).TotalMilliseconds) | Out-File $LogFile -Append -Width 300 + write-Output ("NetworkServerTime (ms): " +$data.NetworkServerTime) | Out-File $LogFile -Append -Width 300 + write-Output ("Execution Time (ms) : " +$data.ExecutionTime) | Out-File $LogFile -Append -Width 300 + write-Output ("Connection Time : " +$data.ConnectionTime) | Out-File $LogFile -Append -Width 300 + write-Output ("ServerRoundTrips : " +$data.ServerRoundtrips) | Out-File $LogFile -Append -Width 300 + write-Output ("BuffersReceived : " +$data.BuffersReceived) | Out-File $LogFile -Append -Width 300 + write-Output ("SelectRows : " +$data.SelectRows) | Out-File $LogFile -Append -Width 300 + write-Output ("SelectCount : " +$data.SelectCount) | Out-File $LogFile -Append -Width 300 + write-Output ("BytesSent : " +$data.BytesSent) | Out-File $LogFile -Append -Width 300 + write-Output ("BytesReceived : " +$data.BytesReceived) | Out-File $LogFile -Append -Width 300 + write-Output "-------------------------" | Out-File $LogFile -Append -Width 300 } } catch { - Write-Output -ForegroundColor DarkYellow "You're WRONG" | Out-File e:\my.log -Append -Width 300 - Write-Output -ForegroundColor Magenta $Error[0].Exception | Out-File e:\my.log -Append -Width 300 + Write-Output -ForegroundColor DarkYellow "You're WRONG" | Out-File $LogFile -Append -Width 300 + Write-Output -ForegroundColor Magenta $Error[0].Exception | Out-File $LogFile -Append -Width 300 } } -write-Output ("Time spent (ms) Procces : " +$sw.elapsed) | Out-File e:\my.log -Append -Width 300 -write-Output ("Review: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/provider-statistics-for-sql-server") | Out-File e:\my.log -Append -Width 300 +write-Output ("Time spent (ms) Procces : " +$sw.elapsed) | Out-File $LogFile -Append -Width 300 +write-Output ("Review: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/provider-statistics-for-sql-server") | Out-File $LogFile -Append -Width 300 +"Please review " + $LogFile + " for test results" From 9e9f1e61c17fd7d1bf5c82af11c796347543628d Mon Sep 17 00:00:00 2001 From: Yochanan Rachamim Date: Thu, 21 Dec 2017 12:32:58 +0200 Subject: [PATCH 2/2] Update SQLConnectivityTest.ps1 --- SQLConnectivityTest.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SQLConnectivityTest.ps1 b/SQLConnectivityTest.ps1 index c3ca287..67bc779 100644 --- a/SQLConnectivityTest.ps1 +++ b/SQLConnectivityTest.ps1 @@ -1,7 +1,7 @@ -$DatabaseServer = "yochanan.database.windows.net" -$Database = "AdventureWorks" -$Username = "yochanan" -$Password = "P@ssw0rd" +$DatabaseServer = "xxxx.database.windows.net" +$Database = "xxxx" +$Username = "xxxx" +$Password = "xxxx" $Pooling = $true $NumberExecutions =10 $WorkingDirectory = "C:\TEMP\"