├── 0_DatabaseBackup └── toystore.bacpac ├── ElasticDatabaseJobs ├── Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1 │ ├── Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1.nupkg │ └── tools │ │ ├── ElasticDatabaseJobs │ │ ├── ElasticDatabaseJobs.format.ps1xml │ │ ├── ElasticDatabaseJobs.psd1 │ │ ├── Microsoft.Azure.SqlDatabase.Jobs.Client.dll │ │ ├── Microsoft.Azure.SqlDatabase.Jobs.PowerShell.dll │ │ └── en-US │ │ │ └── Microsoft.Azure.SqlDatabase.Jobs.PowerShell.dll-help.xml │ │ ├── ElasticDatabaseJobsCommon.psm1 │ │ ├── InstallElasticDatabaseJobs.ps1 │ │ ├── InstallElasticDatabaseJobsCmdlets.ps1 │ │ ├── InstallElasticDatabaseJobs_0.9.ps1 │ │ ├── InstallElasticDatabaseJobs_1.0.ps1 │ │ ├── Microsoft.Azure.SqlDatabase.ElasticScale.Cryptography.dll │ │ ├── UninstallElasticDatabaseJobs.ps1 │ │ ├── UninstallElasticDatabaseJobs_0.9.ps1 │ │ ├── UninstallElasticDatabaseJobs_1.0.ps1 │ │ ├── UpdateElasticDatabaseJobs.ps1 │ │ ├── UpdateElasticDatabaseJobs_0.9.ps1 │ │ └── UpdateElasticDatabaseJobs_1.0.ps1 └── nuget.exe ├── LICENSE ├── Lesson01 ├── Log │ └── ProvisionAzureSQLDatabase.txt ├── ProvisionAzureSQLDatabase.ps1 ├── ProvisionSQLMI.ps1 └── sqlquery.sql ├── Lesson02 ├── CreateSP.sql ├── DTUCalculator │ ├── Workload │ │ ├── readworkload │ │ │ ├── readworkload.bat │ │ │ └── readworkload.sql │ │ └── writeworkload │ │ │ └── order-insert │ │ │ ├── .vs │ │ │ └── MultithreadedOrderInsertWorkload │ │ │ │ └── v14 │ │ │ │ └── .suo │ │ │ ├── MultithreadedOrderInsert │ │ │ ├── App.config │ │ │ ├── ErrorFormMain.Designer.cs │ │ │ ├── ErrorFormMain.cs │ │ │ ├── ErrorFormMain.resx │ │ │ ├── MultithreadedOrderInsert.csproj │ │ │ ├── MultithreadedOrderInsertMain.Designer.cs │ │ │ ├── MultithreadedOrderInsertMain.cs │ │ │ ├── MultithreadedOrderInsertMain.resx │ │ │ ├── Program.cs │ │ │ ├── Properties │ │ │ │ ├── AssemblyInfo.cs │ │ │ │ ├── Resources.Designer.cs │ │ │ │ ├── Resources.resx │ │ │ │ ├── Settings.Designer.cs │ │ │ │ └── Settings.settings │ │ │ ├── bin │ │ │ │ └── Debug │ │ │ │ │ ├── MultithreadedOrderInsert.exe │ │ │ │ │ ├── MultithreadedOrderInsert.exe.config │ │ │ │ │ ├── MultithreadedOrderInsert.pdb │ │ │ │ │ ├── MultithreadedOrderInsert.vshost.exe │ │ │ │ │ ├── MultithreadedOrderInsert.vshost.exe.config │ │ │ │ │ └── MultithreadedOrderInsert.vshost.exe.manifest │ │ │ └── obj │ │ │ │ └── Debug │ │ │ │ ├── DesignTimeResolveAssemblyReferences.cache │ │ │ │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ │ │ │ ├── MultithreadedInMemoryTableInsert.ErrorDetailsForm.resources │ │ │ │ ├── MultithreadedInMemoryTableInsert.MultithreadedOrderInsertMain.resources │ │ │ │ ├── MultithreadedOrderInsert.Properties.Resources.resources │ │ │ │ ├── MultithreadedOrderInsert.csproj.FileListAbsolute.txt │ │ │ │ ├── MultithreadedOrderInsert.csproj.GenerateResource.Cache │ │ │ │ ├── MultithreadedOrderInsert.csprojResolveAssemblyReference.cache │ │ │ │ ├── MultithreadedOrderInsert.exe │ │ │ │ ├── MultithreadedOrderInsert.pdb │ │ │ │ └── TempPE │ │ │ │ └── Properties.Resources.Designer.cs.dll │ │ │ ├── MultithreadedOrderInsertWorkload.sln │ │ │ └── README.md │ ├── sql-perfmon-cl │ │ ├── SqlDtuPerfmon.exe │ │ └── SqlDtuPerfmon.exe.config │ └── sql-perfmon-log.csv ├── DeleteAzureSQLDB.ps1 ├── DropSP.sql ├── ExecuteQuery.bat ├── FixCompatibilityIssues.sql ├── ImportAzureSQLDB.ps1 ├── SQLAzureMigration-master │ ├── .gitattributes │ ├── .gitignore │ ├── SQLAzureMW │ │ ├── AdvancedSettings.Designer.cs │ │ ├── AdvancedSettings.cs │ │ ├── AdvancedSettings.de.resx │ │ ├── AdvancedSettings.en.resx │ │ ├── AdvancedSettings.es.resx │ │ ├── AdvancedSettings.fr.resx │ │ ├── AdvancedSettings.it.resx │ │ ├── AdvancedSettings.ja.resx │ │ ├── AdvancedSettings.nl.resx │ │ ├── AdvancedSettings.resx │ │ ├── AdvancedSettings.zh-CN.resx │ │ ├── AdvancedSettings.zh-TW.resx │ │ ├── App.config │ │ ├── CreateDatabase.Designer.cs │ │ ├── CreateDatabase.af.resx │ │ ├── CreateDatabase.cs │ │ ├── CreateDatabase.de.resx │ │ ├── CreateDatabase.es.resx │ │ ├── CreateDatabase.fr.resx │ │ ├── CreateDatabase.it.resx │ │ ├── CreateDatabase.ja.resx │ │ ├── CreateDatabase.nl.resx │ │ ├── CreateDatabase.resx │ │ ├── CreateDatabase.zh-CN.resx │ │ ├── CreateDatabase.zh-TW.resx │ │ ├── ErrorHelper.cs │ │ ├── FederationMemberCreate.Designer.cs │ │ ├── FederationMemberCreate.cs │ │ ├── FederationMemberCreate.de.resx │ │ ├── FederationMemberCreate.es.resx │ │ ├── FederationMemberCreate.fr.resx │ │ ├── FederationMemberCreate.ja.resx │ │ ├── FederationMemberCreate.nl.resx │ │ ├── FederationMemberCreate.resx │ │ ├── FederationMemberCreate.zh-CN.resx │ │ ├── FederationMemberCreate.zh-TW.resx │ │ ├── FederationMemberDrop.Designer.cs │ │ ├── FederationMemberDrop.cs │ │ ├── FederationMemberDrop.de.resx │ │ ├── FederationMemberDrop.es.resx │ │ ├── FederationMemberDrop.fr.resx │ │ ├── FederationMemberDrop.ja.resx │ │ ├── FederationMemberDrop.nl.resx │ │ ├── FederationMemberDrop.resx │ │ ├── FederationMemberDrop.zh-CN.resx │ │ ├── FederationMemberDrop.zh-TW.resx │ │ ├── GlobalSuppressions.cs │ │ ├── Migrated rules for SQLAzureMW.ruleset │ │ ├── ModuleSuppressions.cs │ │ ├── Program.cs │ │ ├── Properties │ │ │ ├── AssemblyInfo.cs │ │ │ ├── Resources.Designer.cs │ │ │ ├── Resources.de.resx │ │ │ ├── Resources.es.resx │ │ │ ├── Resources.fr.resx │ │ │ ├── Resources.it.resx │ │ │ ├── Resources.ja.resx │ │ │ ├── Resources.nl.resx │ │ │ ├── Resources.resx │ │ │ ├── Resources.zh-CN.resx │ │ │ └── Resources.zh-TW.resx │ │ ├── SQLAzureMW.csproj │ │ ├── SQLAzureMW_BCPJobs.cs │ │ ├── ScriptWizard.Designer.cs │ │ ├── ScriptWizard.ar-SA.resx │ │ ├── ScriptWizard.cs │ │ ├── ScriptWizard.de.resx │ │ ├── ScriptWizard.es.resx │ │ ├── ScriptWizard.fr.resx │ │ ├── ScriptWizard.it.resx │ │ ├── ScriptWizard.ja.resx │ │ ├── ScriptWizard.nl.resx │ │ ├── ScriptWizard.pt.resx │ │ ├── ScriptWizard.resx │ │ ├── ScriptWizard.zh-CN.resx │ │ ├── ScriptWizard.zh-Hans.resx │ │ ├── ScriptWizard.zh-TW.resx │ │ ├── ScriptWizard.zh.resx │ │ └── WizardSteps.cs │ ├── SQLAzureMWBatchBackup │ │ ├── App.config │ │ ├── ObjectSelector.xml │ │ ├── Program.cs │ │ ├── Properties │ │ │ ├── AssemblyInfo.cs │ │ │ ├── Resources.Designer.cs │ │ │ ├── Resources.de.resx │ │ │ ├── Resources.es.resx │ │ │ ├── Resources.fr.resx │ │ │ ├── Resources.it.resx │ │ │ ├── Resources.ja.resx │ │ │ ├── Resources.nl.resx │ │ │ ├── Resources.resx │ │ │ ├── Resources.zh-CN.resx │ │ │ └── Resources.zh-TW.resx │ │ ├── SQLAzureMWBatchBackup.csproj │ │ ├── SQLObjectFilter │ │ │ ├── ObjectSelector.cs │ │ │ ├── SQLObject.cs │ │ │ ├── SQLObjectAction.cs │ │ │ └── SQLObjectType.cs │ │ └── SourceServer.cs │ ├── SQLAzureMWBatchUpload │ │ ├── App.config │ │ ├── BCPJobProcessHandler.cs │ │ ├── Program.cs │ │ ├── Properties │ │ │ ├── AssemblyInfo.cs │ │ │ ├── Resources.Designer.cs │ │ │ ├── Resources.de.resx │ │ │ ├── Resources.es.resx │ │ │ ├── Resources.fr.resx │ │ │ ├── Resources.it.resx │ │ │ ├── Resources.ja.resx │ │ │ ├── Resources.nl.resx │ │ │ ├── Resources.resx │ │ │ ├── Resources.zh-CN.resx │ │ │ └── Resources.zh-TW.resx │ │ └── SQLAzureMWBatchUpload.csproj │ ├── SQLAzureMWParseTSQL │ │ ├── App.config │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── SQLAzureMWParseTSQL.csproj │ ├── SQLAzureMWUtils │ │ ├── AsyncBCPJobEventArgs.cs │ │ ├── AsyncNotificationEventArgs.cs │ │ ├── AsyncProcessingStatus.cs │ │ ├── AsyncQueueBCPJobArgs.cs │ │ ├── AsyncTabPageEventArgs.cs │ │ ├── BCPCommandCtrl.Designer.cs │ │ ├── BCPCommandCtrl.cs │ │ ├── BCPCommandCtrl.resx │ │ ├── BCPCommandEditor.Designer.cs │ │ ├── BCPCommandEditor.cs │ │ ├── BCPCommandEditor.de.resx │ │ ├── BCPCommandEditor.es.resx │ │ ├── BCPCommandEditor.fr.resx │ │ ├── BCPCommandEditor.ja.resx │ │ ├── BCPCommandEditor.nl.resx │ │ ├── BCPCommandEditor.resx │ │ ├── BCPCommandEditor.zh-CN.resx │ │ ├── BCPCommandEditor.zh-TW.resx │ │ ├── BCPCommandProcessor.cs │ │ ├── BCPJobInfo.cs │ │ ├── Collation.cs │ │ ├── CommentArea.cs │ │ ├── CommentAreaHelper.cs │ │ ├── CommonFunc.cs │ │ ├── ConsoleMigrationOutput.cs │ │ ├── DatabaseInfo.cs │ │ ├── Dependencies │ │ │ ├── Dependencies.xml │ │ │ ├── Dependency.cs │ │ │ └── DependencyHelper.cs │ │ ├── Federation │ │ │ ├── BCPSourceTargetWorking.cs │ │ │ ├── FederationCommonFuncs.cs │ │ │ ├── FederationDetails.cs │ │ │ ├── FederationMemberDistribution.cs │ │ │ ├── FederationTableInfo.cs │ │ │ └── FederationWizardSteps.cs │ │ ├── GlobalSuppressions.cs │ │ ├── IConfigurationData.cs │ │ ├── IMigrationOutput.cs │ │ ├── Migrated rules for SQLAzureMWUtils.ruleset │ │ ├── NotificationEventFunctionCode.cs │ │ ├── Properties │ │ │ ├── AssemblyInfo.cs │ │ │ ├── Resources.Designer.cs │ │ │ ├── Resources.It.resx │ │ │ ├── Resources.de.resx │ │ │ ├── Resources.es.resx │ │ │ ├── Resources.fr.resx │ │ │ ├── Resources.ja.resx │ │ │ ├── Resources.nl.resx │ │ │ ├── Resources.resx │ │ │ ├── Resources.zh-CN.resx │ │ │ └── Resources.zh-TW.resx │ │ ├── Retry.cs │ │ ├── RetryLimitExceededException.cs │ │ ├── RetryPolicy.cs │ │ ├── Returns.cs │ │ ├── RulesEngine │ │ │ ├── NotSupported.cs │ │ │ ├── NotSupportedByAzureFile.Config │ │ │ ├── NotSupportedIndex.cs │ │ │ ├── NotSupportedList.cs │ │ │ ├── NotSupportedSchema.cs │ │ │ ├── NotSupportedTable.cs │ │ │ ├── NotSupportedViews.cs │ │ │ ├── SMOScriptOptions.cs │ │ │ ├── SupportedStatement.cs │ │ │ ├── SupportedStatementList.cs │ │ │ └── TSQLNotSupportedByAzure.cs │ │ ├── SQLAzureMWUtils.csproj │ │ ├── ScriptDatabase.cs │ │ ├── ServerConnect.cs │ │ ├── ServerConnect.de.resx │ │ ├── ServerConnect.designer.cs │ │ ├── ServerConnect.es.resx │ │ ├── ServerConnect.fr.resx │ │ ├── ServerConnect.it.resx │ │ ├── ServerConnect.ja.resx │ │ ├── ServerConnect.nl.resx │ │ ├── ServerConnect.resx │ │ ├── ServerConnect.zh-CN.resx │ │ ├── ServerConnect.zh-TW.resx │ │ ├── ServerTypes.cs │ │ ├── SourceProcessor.cs │ │ ├── SqlHelper.cs │ │ ├── TargetProcessor.cs │ │ ├── TargetServerInfo.cs │ │ └── TsqlFileMigrator.cs │ └── SQLAzureMigration.sln ├── ScaleUpAzureSQLDB.ps1 ├── VerifyMigration.sql └── toystore.bak ├── Lesson03 ├── BackupAzureSQLDBToAzureStorage.ps1 ├── toystore.bacpac └── toystore.zip ├── Lesson04 ├── GeoRestoreAzureSQLDB.ps1 ├── InsertNewColor.sql └── PITRAzureSQLDB.ps1 ├── Lesson05 ├── Activity A-1.sql ├── Activity A-2.sql ├── AdvancedThreatProtection │ ├── BruteForceAttack │ │ ├── BruteForceAttack.exe │ │ └── BruteForceAttack.exe.config │ └── SQLInjection │ │ ├── SQLInjection.exe │ │ └── SQLInjection.exe.config ├── BruteForceAttack │ ├── .gitattributes │ ├── .gitignore │ ├── BruteForceAttack.sln │ └── BruteForceAttack │ │ ├── App.config │ │ ├── BruteForceAttack.csproj │ │ ├── Program.cs │ │ └── Properties │ │ └── AssemblyInfo.cs ├── Exercise_ContainedDatabaseUsers.sql ├── Exercise_DatabaseLevelFirewallRules.sql ├── Exercise_ServerLevelFirewallRules.sql └── SQLInjection │ ├── .gitattributes │ ├── .gitignore │ ├── SQLInjection.sln │ └── SQLInjection │ ├── App.config │ ├── Program.cs │ ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings │ ├── SQLInjection.Designer.cs │ ├── SQLInjection.cs │ ├── SQLInjection.csproj │ └── SQLInjection.resx ├── Lesson06 ├── Certificate │ ├── toyfactory.cer │ ├── toyfactory.pfx │ └── toyfactory.pvk ├── Elastic DB tool scripts │ ├── GetMappings.ps1 │ ├── GetShards.ps1 │ ├── ShardManagement │ │ ├── Microsoft.Azure.SqlDatabase.ElasticScale.Client.dll │ │ ├── Microsoft.Azure.SqlDatabase.ElasticScale.Client │ │ │ ├── Microsoft.Azure.SqlDatabase.ElasticScale.Client.nupkg │ │ │ └── lib │ │ │ │ └── net45 │ │ │ │ ├── Microsoft.Azure.SqlDatabase.ElasticScale.Client.dll │ │ │ │ └── Microsoft.Azure.SqlDatabase.ElasticScale.Client.xml │ │ ├── ShardManagement.psm1 │ │ └── nuget.exe │ └── Upgrade.ps1 ├── ElasticQueries.sql ├── Executions.txt ├── Sharding │ ├── Log │ │ ├── Shard-toystore.txt │ │ └── Sharding.txt │ ├── Sharding.ps1 │ ├── TableScripts │ │ ├── 1_CreateSchemas.sql │ │ ├── 2_Application.Countries.sql │ │ ├── 3_Sales.Customer.sql │ │ └── 4_Sales.Orders.sql │ └── toystore-Add-Shards.ps1 ├── Splitting │ ├── Certificate │ │ ├── toyfactory.cer │ │ ├── toyfactory.pfx │ │ └── toyfactory.pvk │ ├── Log │ │ └── SplitToyStoreShard.txt │ ├── SplitMerge │ │ └── SplitMerge.psm1 │ ├── SplitMergeLibraries │ │ └── EnterpriseLibrary.TransientFaultHandling.6.0.1304.0 │ │ │ └── EnterpriseLibrary.TransientFaultHandling.6.0.1304.0.nupkg │ ├── SplitToyStoreShard.ps1 │ └── nuget.exe ├── VerticalScaling │ ├── Set-AzureSqlDatabaseEdition.ps1 │ ├── Start-Workload.ps1 │ └── workload.sql └── certificate.txt ├── Lesson07 ├── ElasticDatabaseJob.sql ├── ElasticPool │ └── Manage-ElasticPool.ps1 └── Execution.txt ├── Lesson08 ├── ActiveGeoReplication │ ├── Executions.txt │ ├── Manage-ActiveGeoReplication.ps1 │ └── Manage-FailoverGroup.ps1 ├── Activity_AcceleratedDatabaseRecovery.sql └── Execution.txt ├── Lesson09 ├── Azure SQL Database Diagnostic Information Queries.sql ├── CreateExtendedEvent.sql ├── InMemoryOLTP │ ├── Cleanup.sql │ ├── CreateObjects.Sql │ ├── Execute.txt │ └── Start-Workload.ps1 ├── IntelligentInsights │ ├── Blocking1.ps1 │ ├── Blocking2.ps1 │ ├── Blocking3.ps1 │ ├── HighIO1.ps1 │ ├── HighIO_Timeouts.ps1 │ └── PowerBiReport.pbix ├── MonitoringDMVs.sql ├── ReadExtendedEventData.sql ├── Start-Workload.ps1 └── workload.sql ├── Lesson10 ├── ActivityMachineLearning.sql ├── ConfigureDataSync.ps1 ├── ProvisionAzureSQLDatabase.ps1 └── monthlysales.dat └── README.md /0_DatabaseBackup/toystore.bacpac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/0_DatabaseBackup/toystore.bacpac -------------------------------------------------------------------------------- /ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1.nupkg -------------------------------------------------------------------------------- /ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/ElasticDatabaseJobs/ElasticDatabaseJobs.format.ps1xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/ElasticDatabaseJobs/ElasticDatabaseJobs.format.ps1xml -------------------------------------------------------------------------------- /ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/ElasticDatabaseJobs/ElasticDatabaseJobs.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/ElasticDatabaseJobs/ElasticDatabaseJobs.psd1 -------------------------------------------------------------------------------- /ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.Client.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.Client.dll -------------------------------------------------------------------------------- /ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.PowerShell.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.PowerShell.dll -------------------------------------------------------------------------------- /ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/ElasticDatabaseJobsCommon.psm1: -------------------------------------------------------------------------------- 1 | ########################################################################################################################### 2 | ### Common helper methods for Elastic Database Jobs Install/Update Scripts 3 | ### 4 | ########################################################################################################################### 5 | 6 | function Log([Parameter(ValueFromPipeline=$true)]$Message, $LogColor = "Cyan") 7 | { 8 | if(-not $NoHost) 9 | { 10 | Write-Host $Message -ForegroundColor $LogColor 11 | } 12 | else 13 | { 14 | Write-Output $Message 15 | } 16 | } 17 | 18 | function GetSqlDatabaseConnectionStringNoPassword() 19 | { 20 | param ( 21 | [Parameter(Mandatory=$true)][string]$AzureSqlServerName, 22 | [Parameter(Mandatory=$false)][string]$AzureSqlDatabaseDnsSuffix = "", 23 | [Parameter(Mandatory=$true)][string]$AzureSqlDatabaseName, 24 | [Parameter(Mandatory=$true)][string]$SqlServerAdministratorUserName 25 | ) 26 | 27 | "Server=$AzureSqlServerName$AzureSqlDatabaseDnsSuffix; Database=$($AzureSqlDatabaseName); User ID=$SqlServerAdministratorUserName; Encrypt=true; TrustServerCertificate=false" 28 | } 29 | 30 | function GetSqlDatabaseConnectionStringWithPassword() 31 | { 32 | param ( 33 | [Parameter(Mandatory=$true)][string]$DatabaseConnectionStringNoPassword, 34 | [Parameter(Mandatory=$true)][string]$SqlServerAdministratorPassword 35 | ) 36 | 37 | "$DatabaseConnectionStringNoPassword;Password=$SqlServerAdministratorPassword" 38 | } 39 | 40 | function TestSqlServerDatabaseConnection 41 | { 42 | param ( 43 | [Parameter(Mandatory=$true)][string]$AzureSqlDatabaseConnectionString 44 | ) 45 | 46 | Log "Azure Sql Database connection string: $AzureSqlDatabaseConnectionString" 47 | 48 | while($true) 49 | { 50 | # Verify connection strings 51 | Log "Attempting to connect to Azure SQL Database" 52 | $sqlConn = New-Object -TypeName "System.Data.SqlClient.SqlConnection" -ArgumentList $AzureSqlDatabaseConnectionString 53 | 54 | try 55 | { 56 | $sqlConn.Open() 57 | Log "Successfully connected to Azure SQL Database" 58 | return 59 | } 60 | catch 61 | { 62 | Log $_.Exception.Message 63 | Log "Sleeping for 10 seconds before retrying" 64 | Start-Sleep -Seconds 10 65 | } 66 | finally 67 | { 68 | $sqlConn.Dispose() 69 | } 70 | } 71 | 72 | Log "Successfully connected to Azure Sql Database" 73 | return $databaseConnectionStringNoPassword 74 | } 75 | 76 | function LoadCryptographyAssembly() 77 | { 78 | $EdjCryptographyAssembly = "$PSScriptRoot\Microsoft.Azure.SqlDatabase.ElasticScale.Cryptography.dll" 79 | Log "Loading assembly $EdjCryptographyAssembly" 80 | Unblock-File $EdjCryptographyAssembly 81 | Add-Type -Path $EdjCryptographyAssembly 82 | } 83 | -------------------------------------------------------------------------------- /ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/InstallElasticDatabaseJobsCmdlets.ps1: -------------------------------------------------------------------------------- 1 | ########################################################################################################################### 2 | ### Install Elastic Database Jobs Cmdlets Script 3 | ### 4 | ### This script installs the Elastic Database Jobs cmdlets to the current user's PowerShell module path. 5 | ### 6 | ### Parameters: 7 | ### $SourceDirectory: Specifies the folder that contains the ElasticDatabaseJobs module folder. 8 | ########################################################################################################################### 9 | 10 | param ( 11 | [Parameter(Position=0)]$SourceDirectory = "." 12 | ) 13 | 14 | $sourceDir = "$PSScriptRoot\ElasticDatabaseJobs" 15 | $psModuleDir = "$env:userprofile\Documents\WindowsPowerShell\Modules" 16 | $null = mkdir $psModuleDir -Force 17 | copy $sourceDir $psModuleDir -Recurse -Force -------------------------------------------------------------------------------- /ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/Microsoft.Azure.SqlDatabase.ElasticScale.Cryptography.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/Microsoft.Azure.SqlDatabase.ElasticScale.Cryptography.dll -------------------------------------------------------------------------------- /ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/UninstallElasticDatabaseJobs.ps1: -------------------------------------------------------------------------------- 1 | ####################################################################################################### 2 | ### Uninstall Elastic Database Jobs Script 3 | ### 4 | ### This script uninstalls the Elastic Database Jobs component from the current Azure subscription. 5 | ### 6 | ### Parameters: 7 | ### $ResourceGroupName: Specifies the resource group for the existing installation. 8 | ### It is recommended to use the default setting of __ElasticDatabaseJob 9 | ### since Azure Portal uses this resource group name to identify 10 | ### Elastic Database Job installations. 11 | ####################################################################################################### 12 | 13 | param ( 14 | $ResourceGroupName = "__ElasticDatabaseJob", 15 | [switch]$NoPrompt 16 | ) 17 | 18 | Set-StrictMode -Version Latest 19 | $ErrorActionPreference = "Stop" 20 | 21 | Import-Module Azure 22 | $azureModule = Get-Module Azure 23 | if ($azureModule.Version -ge '1.0') 24 | { 25 | &$PSScriptRoot\UninstallElasticDatabaseJobs_1.0.ps1 @PSBoundParameters 26 | } 27 | elseif ($azureModule.Version -ge '0.9') 28 | { 29 | &$PSScriptRoot\UninstallElasticDatabaseJobs_0.9.ps1 @PSBoundParameters 30 | } 31 | else 32 | { 33 | throw "Azure PowerShell version $($azureModule.Version) is not supported by this Elastic Database Jobs script." 34 | } 35 | -------------------------------------------------------------------------------- /ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/UninstallElasticDatabaseJobs_0.9.ps1: -------------------------------------------------------------------------------- 1 | ####################################################################################################### 2 | ### Uninstall Elastic Database Jobs Script 3 | ### 4 | ### This script uninstalls the Elastic Database Jobs component from the current Azure subscription. 5 | ### 6 | ### Parameters: 7 | ### $ResourceGroupName: Specifies the resource group for the existing installation. 8 | ### It is recommended to use the default setting of __ElasticDatabaseJob 9 | ### since Azure Portal uses this resource group name to identify 10 | ### Elastic Database Job installations. 11 | ####################################################################################################### 12 | 13 | param ( 14 | $ResourceGroupName = "__ElasticDatabaseJob", 15 | [switch]$NoPrompt 16 | ) 17 | 18 | Switch-AzureMode AzureResourceManager 19 | 20 | $resourceGroup = Get-AzureResourceGroup -Name $ResourceGroupName -ErrorAction SilentlyContinue 21 | if(!$resourceGroup) 22 | { 23 | Write-Host "The Azure Resource Group: $ResourceGroupName has already been deleted. Elastic database job is uninstalled." 24 | return 25 | } 26 | 27 | if (-not $NoPrompt) 28 | { 29 | Write-Host "All Elastic Database Jobs Azure components and its stored data will be be deleted if uninstall is continued." 30 | Write-Host "If you would like to continue with uninstallation, press enter. To quit, press Control-C." -ForegroundColor Yellow 31 | Read-Host 32 | } 33 | 34 | Write-Host "Removing the Azure Resource Group: $ResourceGroupName. This may take a few minutes.” 35 | Remove-AzureResourceGroup -Name $ResourceGroupName -Force 36 | Write-Host "Completed removing the Azure Resource Group: $ResourceGroupName. Elastic database job is now uninstalled." 37 | -------------------------------------------------------------------------------- /ElasticDatabaseJobs/Microsoft.Azure.SqlDatabase.Jobs.0.8.3362.1/tools/UninstallElasticDatabaseJobs_1.0.ps1: -------------------------------------------------------------------------------- 1 | ####################################################################################################### 2 | ### Uninstall Elastic Database Jobs Script 3 | ### 4 | ### This script uninstalls the Elastic Database Jobs component from the current Azure subscription. 5 | ### 6 | ### Parameters: 7 | ### $ResourceGroupName: Specifies the resource group for the existing installation. 8 | ### It is recommended to use the default setting of __ElasticDatabaseJob 9 | ### since Azure Portal uses this resource group name to identify 10 | ### Elastic Database Job installations. 11 | ####################################################################################################### 12 | 13 | param ( 14 | $ResourceGroupName = "__ElasticDatabaseJob", 15 | [switch]$NoPrompt 16 | ) 17 | 18 | $resourceGroup = Get-AzureRmResourceGroup -Name $ResourceGroupName -ErrorAction SilentlyContinue 19 | if(!$resourceGroup) 20 | { 21 | Write-Host "The Azure Resource Group: $ResourceGroupName has already been deleted. Elastic database job is uninstalled." 22 | return 23 | } 24 | 25 | if (-not $NoPrompt) 26 | { 27 | Write-Host "All Elastic Database Jobs Azure components and its stored data will be be deleted if uninstall is continued." 28 | Write-Host "If you would like to continue with uninstallation, press enter. To quit, press Control-C." -ForegroundColor Yellow 29 | Read-Host 30 | } 31 | 32 | Write-Host "Removing the Azure Resource Group: $ResourceGroupName. This may take a few minutes.” 33 | Remove-AzureRmResourceGroup -Name $ResourceGroupName -Force 34 | Write-Host "Completed removing the Azure Resource Group: $ResourceGroupName. Elastic database job is now uninstalled." 35 | -------------------------------------------------------------------------------- /ElasticDatabaseJobs/nuget.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/ElasticDatabaseJobs/nuget.exe -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Training By Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Lesson01/sqlquery.sql: -------------------------------------------------------------------------------- 1 | -- create a new orders table 2 | CREATE TABLE orders 3 | ( 4 | orderid INT IDENTITY(1, 1) PRIMARY KEY, 5 | quantity INT, 6 | sales MONEY 7 | ); 8 | 9 | --populate Orders table with sample data 10 | ; 11 | WITH t1 12 | AS (SELECT 1 AS a 13 | UNION ALL 14 | SELECT 1), 15 | t2 16 | AS (SELECT 1 AS a 17 | FROM t1 18 | CROSS JOIN t1 AS b), 19 | t3 20 | AS (SELECT 1 AS a 21 | FROM t2 22 | CROSS JOIN t2 AS b), 23 | t4 24 | AS (SELECT 1 AS a 25 | FROM t3 26 | CROSS JOIN t3 AS b), 27 | t5 28 | AS (SELECT 1 AS a 29 | FROM t4 30 | CROSS JOIN t4 AS b), 31 | nums 32 | AS (SELECT Row_number() 33 | OVER ( 34 | ORDER BY (SELECT NULL)) AS n 35 | FROM t5) 36 | INSERT INTO orders 37 | SELECT n, 38 | n * 10 39 | FROM nums; 40 | GO 41 | SELECT TOP 10 * from orders; -------------------------------------------------------------------------------- /Lesson02/CreateSP.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | USE [toystore] 4 | GO 5 | create proc [dbo].[BackUpDatabase] 6 | as 7 | backup database toystore to disk = 'C:\torystore.bak' 8 | with init, stats=10 9 | GO 10 | create proc [dbo].[EmailProc] 11 | as 12 | EXEC msdb.dbo.sp_send_dbmail 13 | @profile_name = 'toystore Administrator', 14 | @recipients = 'yourfriend@toystore.com', 15 | @body = 'The stored procedure finished successfully.', 16 | @subject = 'Automated Success Message' ; 17 | go 18 | create Proc [dbo].[Enable_CDC] 19 | as 20 | EXEC sys.sp_cdc_enable_db 21 | GO 22 | create proc [dbo].[ExceuteSQLJob] 23 | as 24 | begin 25 | EXEC msdb.dbo.sp_start_job N'Weekly Sales Data Backup' ; 26 | end 27 | GO 28 | create proc [dbo].[Multipart] 29 | as 30 | select * from toystore.dbo.CITY 31 | 32 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/readworkload/readworkload.bat: -------------------------------------------------------------------------------- 1 | rem Code is reviewed and is in working condition 2 | ostress -S.\sql2016 -Usa -Psql@2016 -dtoystore -iC:\Code\Lesson02\DTUCalculator\Workload\readworkload\readworkload.sql -n500 -r2 -q -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/readworkload/readworkload.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | EXEC [Website].[SearchForPeople] 4 | @SearchText = N'a', 5 | @MaximumRowsToReturn = 1000 6 | GO 7 | EXEC [Website].[SearchForPeople] 8 | @SearchText = N'abc', 9 | @MaximumRowsToReturn = 1000 10 | GO 11 | EXEC [Website].[SearchForPeople] 12 | @SearchText = N'john', 13 | @MaximumRowsToReturn = 1000 14 | GO 15 | EXEC [Website].[SearchForPeople] 16 | @SearchText = N'joh', 17 | @MaximumRowsToReturn = 1000 18 | GO 19 | EXEC [Website].[SearchForStockItems] 20 | @SearchText = N'a', 21 | @MaximumRowsToReturn = 1000 22 | GO 23 | EXEC [Website].[SearchForStockItems] 24 | @SearchText = N'afr', 25 | @MaximumRowsToReturn = 1000 26 | GO 27 | EXEC [Website].[SearchForStockItems] 28 | @SearchText = N'leg', 29 | @MaximumRowsToReturn = 1000 30 | GO 31 | 32 | EXEC [Website].[SearchForSuppliers] 33 | @SearchText = N'a', 34 | @MaximumRowsToReturn = 1000 35 | GO 36 | 37 | EXEC [Website].[SearchForSuppliers] 38 | @SearchText = N'b', 39 | @MaximumRowsToReturn = 1000 40 | GO 41 | EXEC [Website].[SearchForSuppliers] 42 | @SearchText = N'c', 43 | @MaximumRowsToReturn = 1000 44 | 45 | GO 46 | EXEC [Website].[SearchForCustomers] 47 | @SearchText = N'c', 48 | @MaximumRowsToReturn = 1000 49 | GO 50 | EXEC [Website].[SearchForCustomers] 51 | @SearchText = N'b', 52 | @MaximumRowsToReturn = 1000 53 | GO 54 | EXEC [Website].[SearchForCustomers] 55 | @SearchText = N'a', 56 | @MaximumRowsToReturn = 1000 57 | GO 58 | EXEC [Website].[SearchForCustomers] 59 | @SearchText = N'd', 60 | @MaximumRowsToReturn = 1000 61 | 62 | 63 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/.vs/MultithreadedOrderInsertWorkload/v14/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/.vs/MultithreadedOrderInsertWorkload/v14/.suo -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/ErrorFormMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace MultithreadedInMemoryTableInsert 12 | { 13 | public partial class ErrorDetailsForm : Form 14 | { 15 | public string ErrorMessage; 16 | 17 | public ErrorDetailsForm() 18 | { 19 | InitializeComponent(); 20 | } 21 | 22 | private void ErrorDetailsForm_Load(object sender, EventArgs e) 23 | { 24 | DetailedErrorMessageTextBox.Text = this.ErrorMessage; 25 | } 26 | 27 | private void OKButton_Click(object sender, EventArgs e) 28 | { 29 | this.Close(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace MultithreadedInMemoryTableInsert 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new MultithreadedOrderInsertMain()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("MultithreadedInMemoryTableInsert")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MultithreadedInMemoryTableInsert")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("35325643-119b-40c9-9f95-be22cb062599")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace MultithreadedOrderInsert.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MultithreadedOrderInsert.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace MultithreadedOrderInsert.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | 26 | [global::System.Configuration.UserScopedSettingAttribute()] 27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 28 | [global::System.Configuration.DefaultSettingValueAttribute("")] 29 | public string WWI_ConnectionString { 30 | get { 31 | return ((string)(this["WWI_ConnectionString"])); 32 | } 33 | set { 34 | this["WWI_ConnectionString"] = value; 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/bin/Debug/MultithreadedOrderInsert.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/bin/Debug/MultithreadedOrderInsert.exe -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/bin/Debug/MultithreadedOrderInsert.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/bin/Debug/MultithreadedOrderInsert.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/bin/Debug/MultithreadedOrderInsert.pdb -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/bin/Debug/MultithreadedOrderInsert.vshost.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/bin/Debug/MultithreadedOrderInsert.vshost.exe -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/bin/Debug/MultithreadedOrderInsert.vshost.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/bin/Debug/MultithreadedOrderInsert.vshost.exe.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/DesignTimeResolveAssemblyReferences.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/DesignTimeResolveAssemblyReferences.cache -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedInMemoryTableInsert.ErrorDetailsForm.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedInMemoryTableInsert.ErrorDetailsForm.resources -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedInMemoryTableInsert.MultithreadedOrderInsertMain.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedInMemoryTableInsert.MultithreadedOrderInsertMain.resources -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedOrderInsert.Properties.Resources.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedOrderInsert.Properties.Resources.resources -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedOrderInsert.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | C:\Code\Lesson02\DTUCalculator\Workload\writeworkload\order-insert\MultithreadedOrderInsert\bin\Debug\MultithreadedOrderInsert.exe.config 2 | C:\Code\Lesson02\DTUCalculator\Workload\writeworkload\order-insert\MultithreadedOrderInsert\bin\Debug\MultithreadedOrderInsert.exe 3 | C:\Code\Lesson02\DTUCalculator\Workload\writeworkload\order-insert\MultithreadedOrderInsert\bin\Debug\MultithreadedOrderInsert.pdb 4 | C:\Code\Lesson02\DTUCalculator\Workload\writeworkload\order-insert\MultithreadedOrderInsert\obj\Debug\MultithreadedOrderInsert.csprojResolveAssemblyReference.cache 5 | C:\Code\Lesson02\DTUCalculator\Workload\writeworkload\order-insert\MultithreadedOrderInsert\obj\Debug\MultithreadedInMemoryTableInsert.ErrorDetailsForm.resources 6 | C:\Code\Lesson02\DTUCalculator\Workload\writeworkload\order-insert\MultithreadedOrderInsert\obj\Debug\MultithreadedInMemoryTableInsert.MultithreadedOrderInsertMain.resources 7 | C:\Code\Lesson02\DTUCalculator\Workload\writeworkload\order-insert\MultithreadedOrderInsert\obj\Debug\MultithreadedOrderInsert.Properties.Resources.resources 8 | C:\Code\Lesson02\DTUCalculator\Workload\writeworkload\order-insert\MultithreadedOrderInsert\obj\Debug\MultithreadedOrderInsert.csproj.GenerateResource.Cache 9 | C:\Code\Lesson02\DTUCalculator\Workload\writeworkload\order-insert\MultithreadedOrderInsert\obj\Debug\MultithreadedOrderInsert.exe 10 | C:\Code\Lesson02\DTUCalculator\Workload\writeworkload\order-insert\MultithreadedOrderInsert\obj\Debug\MultithreadedOrderInsert.pdb 11 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedOrderInsert.csproj.GenerateResource.Cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedOrderInsert.csproj.GenerateResource.Cache -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedOrderInsert.csprojResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedOrderInsert.csprojResolveAssemblyReference.cache -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedOrderInsert.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedOrderInsert.exe -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedOrderInsert.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/MultithreadedOrderInsert.pdb -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsert/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/MultithreadedOrderInsertWorkload.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultithreadedOrderInsert", "MultithreadedOrderInsert\MultithreadedOrderInsert.csproj", "{35325643-119B-40C9-9F95-BE22CB062599}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {35325643-119B-40C9-9F95-BE22CB062599}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {35325643-119B-40C9-9F95-BE22CB062599}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {35325643-119B-40C9-9F95-BE22CB062599}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {35325643-119B-40C9-9F95-BE22CB062599}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/Workload/writeworkload/order-insert/README.md: -------------------------------------------------------------------------------- 1 | # Workload Driver for Order Insertion in WideWorldImporters 2 | 3 | This application simulates an order insertion workload for the WideWorldImporters sample database. 4 | 5 | ### Contents 6 | 7 | [About this sample](#about-this-sample)
8 | [Before you begin](#before-you-begin)
9 | [Running the sample](#run-this-sample)
10 | [Sample details](#sample-details)
11 | [Disclaimers](#disclaimers)
12 | [Related links](#related-links)
13 | 14 | 15 | 16 | 17 | ## About this sample 18 | 19 | 20 | 1. **Applies to:** SQL Server 2016 (or higher), Azure SQL Database 21 | 1. **Key features:** Core database features 22 | 1. **Workload:** OLTP 23 | 1. **Programming Language:** C# 24 | 1. **Authors:** Greg Low, Jos de Bruijn 25 | 1. **Update history:** 25 May 2016 - initial revision 26 | 27 | 28 | 29 | ## Before you begin 30 | 31 | To run this sample, you need the following prerequisites. 32 | 33 | **Software prerequisites:** 34 | 35 | 36 | 1. SQL Server 2016 (or higher) or Azure SQL Database. 37 | 2. Visual Studio 2015. 38 | 3. The WideWorldImporters database. 39 | 40 | 41 | 42 | ## Running the sample 43 | 44 | 1. Open the solution file MultithreadedOrderInsertWorkload.sln in Visual Studio. 45 | 46 | 2. Build the solution. 47 | 48 | 3. Run the app. 49 | 50 | ## Sample details 51 | 52 | This application is used to provide an intensive order entry workload for the WideWorldImporters database. When started it displays the following: 53 | 54 | ![Alt text](/media/wide-world-importers-order-insert-app.png "WideWorldImporters Order Insert Workload Simulation") 55 | 56 | Ensure that the connection string is set appropriately. It is save when the program is edited. If you ever need to set it back to the default value, open the program, clear the string, and exit the program. When you restart the program, the connection string will have been returned to the default value. 57 | 58 | The program uses the selected number of threads to concurrently call the `Website.InsertCustomerOrder` stored procedure. 59 | 60 | When inserts are occurring, click the button to stop but allow time for the system to respond and stop. It may take a few seconds to respond, particularly if a larger number of threads is being used. 61 | 62 | 63 | 64 | 65 | ## Disclaimers 66 | The code included in this sample is not intended to be used for production purposes. 67 | 68 | 69 | -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/sql-perfmon-cl/SqlDtuPerfmon.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/DTUCalculator/sql-perfmon-cl/SqlDtuPerfmon.exe -------------------------------------------------------------------------------- /Lesson02/DTUCalculator/sql-perfmon-cl/SqlDtuPerfmon.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Lesson02/DeleteAzureSQLDB.ps1: -------------------------------------------------------------------------------- 1 | ## Code is reviewed and is in working condition 2 | 3 | Try 4 | { 5 | 6 | Login-AzureRmAccount 7 | $removesqldb = @{ 8 | ResourceGroupName=$resourcegroupname 9 | ServerName=$azuresqlservername; 10 | DatabaseName= $databasename; 11 | } 12 | Remove-AzureRmSqlDatabase; 13 | 14 | 15 | } 16 | catch 17 | { 18 | $ErrorMessage = $_.Exception.Message 19 | $FailedItem = $_.Exception.ItemName 20 | Write-host $ErrorMessage $FailedItem -ForegroundColor Red 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /Lesson02/DropSP.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[BackUpDatabase]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) 4 | BEGIN 5 | drop procedure BackUpDatabase 6 | END 7 | go 8 | IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[EmailProc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) 9 | BEGIN 10 | drop procedure EmailProc 11 | END 12 | go 13 | IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[Enable_CDC]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) 14 | BEGIN 15 | drop procedure Enable_CDC 16 | END 17 | go 18 | IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[ExceuteSQLJob]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) 19 | BEGIN 20 | drop procedure ExceuteSQLJob 21 | END 22 | go 23 | IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[Multipart]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) 24 | BEGIN 25 | drop procedure Multipart 26 | END 27 | go -------------------------------------------------------------------------------- /Lesson02/ExecuteQuery.bat: -------------------------------------------------------------------------------- 1 | rem Code is reviewed and is in working condition 2 | ostress -Stoyfactory.database.windows.net -Usqladmin -PPackt@pub2 -dtoystore -Q"SELECT * FROM Warehouse.StockItems si join Warehouse.StockItemholdings sh on si.StockItemId=sh.StockItemID join Sales.OrderLines ol on ol.StockItemID = si.StockItemID" -n25 -r20 -q -------------------------------------------------------------------------------- /Lesson02/FixCompatibilityIssues.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | USE [toystore] 4 | GO 5 | ALTER proc [dbo].[BackUpDatabase ] 6 | As 7 | -- Backup command isn’t supported on Azure SQL Database 8 | --backup database toystore to disk = 'C:\torystore.bak' 9 | --with init, stats=10 10 | GO 11 | ALTER proc [dbo].[EmailProc] 12 | As 13 | -- Database mail isn’t supported on Azure SQL Database 14 | --EXEC msdb.dbo.sp_send_dbmail 15 | -- @profile_name = 'toystore Administrator', 16 | -- @recipients = 'yourfriend@toystore.com', 17 | -- @body = 'The stored procedure finished successfully.', 18 | -- @subject = 'Automated Success Message' ; 19 | GO 20 | ALTER Proc [dbo].[Enable_CDC] 21 | As 22 | -- Change Data Capture isn’t supported on Azure SQL Database 23 | --EXEC sys.sp_cdc_enable_db 24 | GO 25 | ALTER proc [dbo].[ExceuteSQLJob] 26 | as 27 | --EXEC msdb.dbo.sp_start_job N'Weekly Sales Data Backup' ; 28 | GO 29 | ALTER proc [dbo].[Multipart] 30 | as 31 | --select * from toystore.dbo.city 32 | -- Multipart names other than tempdb aren’t supported on Azure SQL Database 33 | select * from city 34 | -------------------------------------------------------------------------------- /Lesson02/ImportAzureSQLDB.ps1: -------------------------------------------------------------------------------- 1 | ## Code is reviewed and is in working condition 2 | 3 | param( 4 | 5 | [Parameter(Mandatory=$true)] 6 | [string]$servername, 7 | [Parameter(Mandatory=$true)] 8 | [string]$sqldb, 9 | [Parameter(Mandatory=$true)] 10 | [string]$user, 11 | [Parameter(Mandatory=$true)] 12 | [string]$password, 13 | [Parameter(Mandatory=$true)] 14 | [string] $bacpacfilepath, 15 | [Parameter(Mandatory=$true)] 16 | [string] $sqlpackagepath 17 | ) 18 | 19 | #C:\Users\Administrator\Documents\Packtpub\toystore.bacpac 20 | $arguments = "/a:Import /tsn:tcp:$servername.database.windows.net,1433 /tu:$user /tp:$password /tdn:$sqldb /p:DatabaseEdition=Basic /sf:$bacpacfilepath" 21 | #$sqlpackagepath = "C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin\sqlpackage.exe" 22 | 23 | Start-Process -FilePath $sqlpackagepath -ArgumentList $arguments -NoNewWindow -Wait -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMW/AdvancedSettings.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace SQLAzureMW 2 | { 3 | partial class AdvancedSettings 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AdvancedSettings)); 32 | this.pgOptions = new System.Windows.Forms.PropertyGrid(); 33 | this.btnCancel = new System.Windows.Forms.Button(); 34 | this.btnOK = new System.Windows.Forms.Button(); 35 | this.SuspendLayout(); 36 | // 37 | // pgOptions 38 | // 39 | resources.ApplyResources(this.pgOptions, "pgOptions"); 40 | this.pgOptions.Name = "pgOptions"; 41 | // 42 | // btnCancel 43 | // 44 | resources.ApplyResources(this.btnCancel, "btnCancel"); 45 | this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; 46 | this.btnCancel.Name = "btnCancel"; 47 | this.btnCancel.UseVisualStyleBackColor = true; 48 | // 49 | // btnOK 50 | // 51 | resources.ApplyResources(this.btnOK, "btnOK"); 52 | this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; 53 | this.btnOK.Name = "btnOK"; 54 | this.btnOK.UseVisualStyleBackColor = true; 55 | // 56 | // AdvancedSettings 57 | // 58 | resources.ApplyResources(this, "$this"); 59 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 60 | this.Controls.Add(this.btnOK); 61 | this.Controls.Add(this.btnCancel); 62 | this.Controls.Add(this.pgOptions); 63 | this.Name = "AdvancedSettings"; 64 | this.ResumeLayout(false); 65 | 66 | } 67 | 68 | #endregion 69 | 70 | private System.Windows.Forms.PropertyGrid pgOptions; 71 | private System.Windows.Forms.Button btnCancel; 72 | private System.Windows.Forms.Button btnOK; 73 | } 74 | } -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMW/AdvancedSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | using SQLAzureMWUtils; 10 | 11 | namespace SQLAzureMW 12 | { 13 | public partial class AdvancedSettings : Form 14 | { 15 | public SMOScriptOptions GetOptions 16 | { 17 | get { return (SMOScriptOptions) pgOptions.SelectedObject; } 18 | } 19 | 20 | public AdvancedSettings() 21 | { 22 | InitializeComponent(); 23 | } 24 | 25 | public AdvancedSettings(SMOScriptOptions sso) 26 | { 27 | InitializeComponent(); 28 | pgOptions.SelectedObject = sso; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMW/ErrorHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows.Forms; 6 | 7 | namespace SQLAzureMW 8 | { 9 | public static class ErrorHelper 10 | { 11 | public static void ShowException(IWin32Window owner, Exception ex) 12 | { 13 | MessageBox.Show(owner, ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMW/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | // 6 | // To add a suppression to this file, right-click the message in the 7 | // Error List, point to "Suppress Message(s)", and click 8 | // "In Project Suppression File". 9 | // You do not need to add suppressions to this file manually. 10 | 11 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1703:ResourceStringsShouldBeSpelledCorrectly", MessageId = "trc", Scope = "resource", Target = "SQLAzureMW.Properties.Resources.resources")] 12 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMW/ModuleSuppressions.cs: -------------------------------------------------------------------------------- 1 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "SQLAzureMW")] 2 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2007:MarkAssembliesWithReliabilityContract")] 3 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMW/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Windows.Forms; 7 | using System.Xml.Serialization; 8 | using System.Xml.XPath; 9 | using SQLAzureMWUtils; 10 | 11 | namespace SQLAzureMW 12 | { 13 | static class Program 14 | { 15 | /// 16 | /// The main entry point for the application. 17 | /// 18 | [STAThread] 19 | static void Main(String[] args) 20 | { 21 | Application.EnableVisualStyles(); 22 | Application.SetCompatibleTextRenderingDefault(false); 23 | 24 | try 25 | { 26 | string message = ""; 27 | if (DependencyHelper.CheckDependencies(ref message)) 28 | { 29 | Application.Run(new ScriptWizard()); 30 | } 31 | else 32 | { 33 | MessageBox.Show(message, "Dependencies"); 34 | } 35 | } 36 | catch (Exception ex) 37 | { 38 | MessageBox.Show("Sorry! SQLAzureMW encountered an error. Please see additional information to resolve." + Environment.NewLine + ex.ToString()); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMW/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using System.Resources; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("SQLAzureMW")] 10 | [assembly: AssemblyDescription("SQL Server to SQL Database Migration")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("SQLAzureMW")] 14 | [assembly: AssemblyCopyright("Copyright © 2010")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // Setting ComVisible to false makes the types in this assembly not visible 19 | // to COM components. If you need to access a type in this assembly from 20 | // COM, set the ComVisible attribute to true on that type. 21 | [assembly: ComVisible(false)] 22 | 23 | // The following GUID is for the ID of the typelib if this project is exposed to COM 24 | [assembly: Guid("c0e7c66c-3e67-4631-ad8a-77c8a0143389")] 25 | 26 | // Version information for an assembly consists of the following four values: 27 | // 28 | // Major Version 29 | // Minor Version 30 | // Build Number 31 | // Revision 32 | // 33 | // You can specify all the values or you can default the Build and Revision Numbers 34 | // by using the '*' as shown below: 35 | // [assembly: AssemblyVersion("1.0.*")] 36 | [assembly: AssemblyVersion("3.9.15.0")] 37 | [assembly: AssemblyFileVersion("3.9.15.0")] 38 | [assembly: NeutralResourcesLanguageAttribute("en")] 39 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMW/WizardSteps.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLAzureMW 7 | { 8 | public static class WizardSteps 9 | { 10 | public const int SelectProcess = 0; 11 | public const int SelectDatabaseSource = 1; 12 | public const int SelectObjectsToScript = 2; 13 | public const int ScriptWizardSummary = 3; 14 | public const int ResultsSummary = 4; 15 | public const int SetupTargetConnection = 5; 16 | public const int TargetResults = 6; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWBatchBackup/ObjectSelector.xml: -------------------------------------------------------------------------------- 1 |  2 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWBatchBackup/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using System.Resources; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("SQLAzureMWBatchBackup")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("Microsoft")] 13 | [assembly: AssemblyProduct("SQLAzureMWBatchBackup")] 14 | [assembly: AssemblyCopyright("Copyright © Microsoft 2011")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // Setting ComVisible to false makes the types in this assembly not visible 19 | // to COM components. If you need to access a type in this assembly from 20 | // COM, set the ComVisible attribute to true on that type. 21 | [assembly: ComVisible(false)] 22 | 23 | // The following GUID is for the ID of the typelib if this project is exposed to COM 24 | [assembly: Guid("d2619904-7de6-4204-b9f6-6be55b9a370c")] 25 | 26 | // Version information for an assembly consists of the following four values: 27 | // 28 | // Major Version 29 | // Minor Version 30 | // Build Number 31 | // Revision 32 | // 33 | // You can specify all the values or you can default the Build and Revision Numbers 34 | // by using the '*' as shown below: 35 | // [assembly: AssemblyVersion("1.0.*")] 36 | [assembly: AssemblyVersion("3.9.15.0")] 37 | [assembly: AssemblyFileVersion("3.9.15.0")] 38 | [assembly: NeutralResourcesLanguageAttribute("en")] 39 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWBatchBackup/SQLObjectFilter/SQLObjectAction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLAzureMWBatchBackup.SQLObjectFilter 7 | { 8 | public enum SQLObjectAction 9 | { 10 | MatchedAndScript, 11 | MatchedAndDoNotScript, 12 | DidNotMatch 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWBatchBackup/SQLObjectFilter/SQLObjectType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | 7 | namespace SQLAzureMWBatchBackup.SQLObjectFilter 8 | { 9 | public class SQLObjectType 10 | { 11 | private bool _Script; 12 | private List _SQLObjects; 13 | 14 | [XmlAttribute(DataType = "boolean", AttributeName = "script")] 15 | public bool Script 16 | { 17 | get { return _Script; } 18 | set { _Script = value; } 19 | } 20 | 21 | public List SQLObjects 22 | { 23 | get 24 | { 25 | if (_SQLObjects == null) 26 | { 27 | _SQLObjects = new List(); 28 | } 29 | return _SQLObjects; 30 | } 31 | 32 | set 33 | { 34 | _SQLObjects = value; 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWBatchUpload/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using System.Resources; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("SQLAzureMWBatchUpload")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("SQLAzureMWBatchUpload")] 14 | [assembly: AssemblyCopyright("Copyright © 2010")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // Setting ComVisible to false makes the types in this assembly not visible 19 | // to COM components. If you need to access a type in this assembly from 20 | // COM, set the ComVisible attribute to true on that type. 21 | [assembly: ComVisible(false)] 22 | 23 | // The following GUID is for the ID of the typelib if this project is exposed to COM 24 | [assembly: Guid("43ab01ba-654a-4ed6-8569-47dbb46cbdfe")] 25 | 26 | // Version information for an assembly consists of the following four values: 27 | // 28 | // Major Version 29 | // Minor Version 30 | // Build Number 31 | // Revision 32 | // 33 | // You can specify all the values or you can default the Build and Revision Numbers 34 | // by using the '*' as shown below: 35 | // [assembly: AssemblyVersion("1.0.*")] 36 | [assembly: AssemblyVersion("3.9.15.0")] 37 | [assembly: AssemblyFileVersion("3.9.15.0")] 38 | [assembly: NeutralResourcesLanguageAttribute("en")] 39 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWParseTSQL/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWParseTSQL/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SQLAzureMWParseTSQL")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("SQLAzureMWParseTSQL")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("2de1d065-3d69-4557-acbf-daad16d1ecc9")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("3.5.0.0")] 36 | [assembly: AssemblyFileVersion("3.5.0.0")] 37 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/AsyncBCPJobEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows.Forms; 6 | using System.Drawing; 7 | 8 | namespace SQLAzureMWUtils 9 | { 10 | public class AsyncBCPJobEventArgs : EventArgs 11 | { 12 | public RichTextBox ResultsTextBox { get; set; } 13 | public CommandStatus Status { get; set; } 14 | public string DisplayText { get; set; } 15 | public Color DisplayColor { get; set; } 16 | public TabPage CallingTagPage { get; set; } 17 | public bool ClearRTB { get; set; } 18 | public int CurrentThreadIndex { get; set; } 19 | 20 | public AsyncBCPJobEventArgs(TabPage callingTaPage, CommandStatus status, RichTextBox rtb, string displayText, Color displayColor) 21 | { 22 | CallingTagPage = callingTaPage; 23 | Status = status; 24 | ResultsTextBox = rtb; 25 | DisplayText = displayText; 26 | DisplayColor = displayColor; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/AsyncNotificationEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Drawing; 6 | 7 | namespace SQLAzureMWUtils 8 | { 9 | public class AsyncNotificationEventArgs : EventArgs 10 | { 11 | private NotificationEventFunctionCode _functionCode; // 0 = BCPUploadData, 1 = ExecuteSQLonAzure, 2 = ParseFile 12 | // 3 = GenerateScriptFromSQLServer, 4 ScriptDatabase Results, 5 ScriptDatabase TSQL 13 | private string _StatusMsg; 14 | private string _DisplayText; 15 | private int _percentComplete; 16 | private Color _DisplayColor; 17 | 18 | public string StatusMsg 19 | { 20 | get { return _StatusMsg; } 21 | set { _StatusMsg = value; } 22 | } 23 | 24 | public Color DisplayColor 25 | { 26 | get { return _DisplayColor; } 27 | set { _DisplayColor = value; } 28 | } 29 | 30 | public string DisplayText 31 | { 32 | get { return _DisplayText; } 33 | set { _DisplayText = value; } 34 | } 35 | 36 | public int PercentComplete 37 | { 38 | get { return _percentComplete; } 39 | set { _percentComplete = value; } 40 | } 41 | 42 | public NotificationEventFunctionCode FunctionCode 43 | { 44 | get { return _functionCode; } 45 | set { _functionCode = value; } 46 | } 47 | 48 | public AsyncNotificationEventArgs(NotificationEventFunctionCode functionCode, int percentComplete, string statusMessage, string displayText, Color displayColor) 49 | { 50 | _functionCode = functionCode; 51 | _StatusMsg = statusMessage; 52 | _percentComplete = percentComplete; 53 | _DisplayText = displayText; 54 | _DisplayColor = displayColor; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/AsyncProcessingStatus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLAzureMWUtils 7 | { 8 | public static class AsyncProcessingStatus 9 | { 10 | public static bool FinishedAddingJobs = false; 11 | public static bool FinishedProcessingJobs = false; 12 | public static bool CancelProcessing = false; 13 | public static long NumberOfCommands = 0; 14 | public static long NumberOfCommandsExecuted = 0; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/AsyncQueueBCPJobArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLAzureMWUtils 7 | { 8 | public class AsyncQueueBCPJobArgs : EventArgs 9 | { 10 | public BCPJobInfo JobInfo { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/AsyncTabPageEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLAzureMWUtils 7 | { 8 | public class AsyncTabPageEventArgs : EventArgs 9 | { 10 | public bool RemoveTabs { get; set; } 11 | public bool Show { get; set; } 12 | public int CurrentTabIndex { get; set; } 13 | public string DisplayText { get; set; } 14 | 15 | public AsyncTabPageEventArgs(int tabIndex, string displayText) 16 | { 17 | Show = true; 18 | RemoveTabs = false; 19 | CurrentTabIndex = tabIndex; 20 | DisplayText = displayText; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/BCPCommandCtrl.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace SQLAzureMWUtils 2 | { 3 | partial class BCPCommandCtrl 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.rtbResults = new System.Windows.Forms.RichTextBox(); 32 | this.SuspendLayout(); 33 | // 34 | // rtbResults 35 | // 36 | this.rtbResults.Dock = System.Windows.Forms.DockStyle.Fill; 37 | this.rtbResults.Location = new System.Drawing.Point(0, 0); 38 | this.rtbResults.Name = "rtbResults"; 39 | this.rtbResults.Size = new System.Drawing.Size(552, 489); 40 | this.rtbResults.TabIndex = 1; 41 | this.rtbResults.Text = ""; 42 | this.rtbResults.WordWrap = false; 43 | // 44 | // BCPCommandCtrl 45 | // 46 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 47 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 48 | this.Controls.Add(this.rtbResults); 49 | this.Name = "BCPCommandCtrl"; 50 | this.Size = new System.Drawing.Size(552, 489); 51 | this.ResumeLayout(false); 52 | 53 | } 54 | 55 | #endregion 56 | 57 | private System.Windows.Forms.RichTextBox rtbResults; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/BCPCommandEditor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | 10 | namespace SQLAzureMWUtils 11 | { 12 | public partial class BCPCommandEditor : Form 13 | { 14 | public long NumberOfRows 15 | { 16 | get 17 | { 18 | return Convert.ToInt64(tbNumOfRows.Text); 19 | } 20 | } 21 | 22 | public string BCPCommand 23 | { 24 | get 25 | { 26 | return tbBCPCommand.Text; 27 | } 28 | } 29 | 30 | public BCPCommandEditor(long numOfRows, string bcpCmd) 31 | { 32 | InitializeComponent(); 33 | tbBCPCommand.Text = bcpCmd; 34 | tbNumOfRows.Text = numOfRows.ToString(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/BCPJobInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Collections.Specialized; 7 | 8 | namespace SQLAzureMWUtils 9 | { 10 | public enum CommandStatus 11 | { 12 | Failed, 13 | InProcess, 14 | Skip, 15 | Success, 16 | Waiting 17 | } 18 | 19 | public class BCPJobInfo 20 | { 21 | public AsyncUpdateStatus UpdateStatus { get; set; } 22 | public CommandStatus JobStatus { get; set; } 23 | public FederationDetails FederationInfo { get; set; } 24 | public string TableName { get; set; } 25 | public string Schema { get; set; } 26 | public string BCPUploadCommand { get; set; } 27 | public string ConnectionString { get; set; } 28 | public Int64 NumberOfRows { get; set; } 29 | public int AssignedTabIndex { get; set; } 30 | public int CurrentThreadIndex { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/CommentArea.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLAzureMWUtils 7 | { 8 | public class CommentArea 9 | { 10 | public int Start { get; set; } 11 | public int End { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/ConsoleMigrationOutput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace SQLAzureMWUtils 5 | { 6 | /// 7 | /// This is the ConsoleMigrationOutput class. 8 | /// 9 | /// 10 | /// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 11 | /// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | /// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 13 | /// PARTICULAR PURPOSE. 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// Added headers, etc. 19 | /// 20 | /// 21 | public class ConsoleMigrationOutput : IMigrationOutput 22 | { 23 | public string OutputFile { get; private set; } 24 | public bool ShouldWriteToConsole { get; private set; } 25 | 26 | public ConsoleMigrationOutput(string outputFile, bool shouldWriteToConsole) 27 | { 28 | OutputFile = outputFile; 29 | ShouldWriteToConsole = shouldWriteToConsole; 30 | } 31 | 32 | public void StatusUpdateHandler(AsyncNotificationEventArgs args) 33 | { 34 | WriteToFile(args); 35 | WriteToConsole(args); 36 | } 37 | 38 | private void WriteToFile(AsyncNotificationEventArgs args) 39 | { 40 | if (!string.IsNullOrEmpty(OutputFile)) 41 | { 42 | if (args.FunctionCode == NotificationEventFunctionCode.SqlOutput) 43 | { 44 | File.AppendAllText(OutputFile, args.DisplayText); 45 | } 46 | } 47 | } 48 | 49 | private void WriteToConsole(AsyncNotificationEventArgs args) 50 | { 51 | if (ShouldWriteToConsole) 52 | { 53 | Console.Write(args.DisplayText); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/DatabaseInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.SqlServer.Management.Smo; 6 | 7 | namespace SQLAzureMWUtils 8 | { 9 | public enum TypeOfConnection 10 | { 11 | SQLAzureFederation = 0 12 | , UsingSMO = 1 13 | , UsingADO = 2 14 | } 15 | 16 | public class DatabaseInfo 17 | { 18 | public TypeOfConnection ConnectedTo = TypeOfConnection.UsingSMO; 19 | public FederationMemberDistribution FederationMember { get; set; } 20 | public Database DatabaseObject { get; set; } 21 | public string DatabaseName { get; set; } 22 | public bool IsDbOwner { get; set; } 23 | 24 | public override string ToString() 25 | { 26 | if (ConnectedTo == TypeOfConnection.SQLAzureFederation) 27 | { 28 | return FederationMember.ToString(); 29 | } 30 | else if (DatabaseObject == null) 31 | { 32 | return "[" + DatabaseName + "]"; 33 | } 34 | return DatabaseObject.ToString(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/Dependencies/Dependencies.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 5 | Microsoft.SqlServer.Management.Smo.Server 6 | 7 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/Dependencies/Dependency.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLAzureMWUtils 7 | { 8 | public class Dependency 9 | { 10 | public string Assembly { get; set; } 11 | public string Type { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/Dependencies/DependencyHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | 7 | namespace SQLAzureMWUtils 8 | { 9 | public static class DependencyHelper 10 | { 11 | private static List _dependencies = null; 12 | 13 | public static List Dependencies 14 | { 15 | get 16 | { 17 | if (_dependencies == null) 18 | { 19 | try 20 | { 21 | string file = CommonFunc.GetAppSettingsStringValue("DependencyFile"); 22 | if (file.Length > 0) 23 | { 24 | string dependsOn = CommonFunc.GetTextFromFile(file); 25 | if (dependsOn.Length > 0) 26 | { 27 | _dependencies = (List)CommonFunc.DeserializeXmlString(dependsOn, typeof(List)); 28 | } 29 | } 30 | } 31 | catch (Exception ex) 32 | { 33 | System.Diagnostics.Debug.WriteLine(CommonFunc.FormatString(Properties.Resources.DependencyCheckerFileNotFound, ex.Message)); 34 | } 35 | 36 | if (_dependencies == null) 37 | { 38 | _dependencies = new List(); 39 | } 40 | } 41 | return _dependencies; 42 | } 43 | } 44 | 45 | public static bool CheckDependencies(ref string message) 46 | { 47 | // Create an instance of dependent classes in a new AppDomain 48 | try 49 | { 50 | AppDomain newAppDomain = AppDomain.CreateDomain("DependencyChecker"); 51 | foreach (Dependency depOn in Dependencies) 52 | { 53 | newAppDomain.CreateInstance(depOn.Assembly, depOn.Type); 54 | } 55 | } 56 | catch (Exception ex) 57 | { 58 | Assembly assem = Assembly.GetEntryAssembly(); 59 | AssemblyName assemName = assem.GetName(); 60 | 61 | message = CommonFunc.FormatString(Properties.Resources.ErrorMissingDependencies, assemName.Name, ex.Message); 62 | return false; 63 | } 64 | return true; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/Federation/BCPSourceTargetWorking.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLAzureMWUtils 7 | { 8 | public class BCPSourceTargetWorking 9 | { 10 | public FederationTableInfo TableInformation { get; set; } 11 | public string TargetDatabase { get; set; } 12 | public string BCPCommand { get; set; } 13 | public string OutputFileName { get; set; } 14 | public long NumberOfRows { get; set; } 15 | 16 | public override string ToString() 17 | { 18 | return BCPCommand; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/Federation/FederationDetails.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLAzureMWUtils 7 | { 8 | public class FederationDetails 9 | { 10 | public int Federation_id { get; set; } 11 | public string FederationName { get; set; } 12 | private List _Members; 13 | 14 | public List Members 15 | { 16 | get 17 | { 18 | if (_Members == null) 19 | { 20 | _Members = new List(); 21 | } 22 | return _Members; 23 | } 24 | } 25 | 26 | public override string ToString() 27 | { 28 | return FederationName; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/Federation/FederationMemberDistribution.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace SQLAzureMWUtils 5 | { 6 | public class FederationMemberDistribution 7 | { 8 | public string DistrubutionName { get; set; } 9 | public string DatabaseName { get; set; } 10 | public string Low { get; set; } 11 | public string High { get; set; } 12 | public string FedType { get; set; } 13 | public List Tables = new List(); 14 | public int Member_ID { get; set; } 15 | 16 | public override string ToString() 17 | { 18 | if (FedType.Equals("root")) return "Root"; 19 | 20 | string tmpLow = Low; 21 | string tmpHigh = High; 22 | 23 | if (High.Length == 0) 24 | { 25 | tmpHigh = "Max"; 26 | } 27 | 28 | switch (FedType) 29 | { 30 | case "int": 31 | if (Low == "-2147483648") 32 | { 33 | tmpLow = "Min"; 34 | } 35 | break; 36 | 37 | case "uniqueidentifier": 38 | if (Low == "00000000-0000-0000-0000-000000000000") 39 | { 40 | tmpLow = "Min"; 41 | } 42 | break; 43 | 44 | case "varbinary": 45 | if (Low == "0x") 46 | { 47 | tmpLow = "Min"; 48 | } 49 | break; 50 | 51 | default: 52 | if (Low == "-9223372036854775808") 53 | { 54 | tmpLow = "Min"; 55 | } 56 | break; 57 | } 58 | 59 | return DistrubutionName + " (" + tmpLow + " to " + tmpHigh + ")"; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/Federation/FederationTableInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SQLAzureMWUtils 6 | { 7 | public class FederationTableInfo 8 | { 9 | public string Schema { get; set; } 10 | public string Table { get; set; } 11 | public string FederatedColumn { get; set; } 12 | public string BCPArgs { get; set; } 13 | public string InputFileName { get; set; } 14 | public string HastableKey { get; set; } 15 | 16 | public override string ToString() 17 | { 18 | return "[" + Schema + "].[" + Table + "]"; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/Federation/FederationWizardSteps.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLAzureMWUtils 7 | { 8 | public class FederationWizardSteps 9 | { 10 | public const int SelectServers = 0; 11 | public const int DownloadSummary = 1; 12 | public const int ResultsSummary = 2; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage 2 | // attributes that are applied to this project. 3 | // Project-level suppressions either have no target or are given 4 | // a specific target and scoped to a namespace, type, member, etc. 5 | // 6 | // To add a suppression to this file, right-click the message in the 7 | // Error List, point to "Suppress Message(s)", and click 8 | // "In Project Suppression File". 9 | // You do not need to add suppressions to this file manually. 10 | 11 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "SQL")] 12 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "SQL", Scope = "namespace", Target = "SQLAzureMWUtils")] 13 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Utils", Scope = "namespace", Target = "SQLAzureMWUtils")] 14 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Utils")] 15 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1306:SetLocaleForDataTypes", Scope = "member", Target = "SQLAzureMWUtils.SqlHelper.#ExecuteDataset(System.Data.SqlClient.SqlTransaction,System.Data.CommandType,System.String,System.Data.SqlClient.SqlParameter[])")] 16 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1306:SetLocaleForDataTypes", Scope = "member", Target = "SQLAzureMWUtils.SqlHelper.#ExecuteDataset(System.Data.SqlClient.SqlConnection,System.Data.CommandType,System.String,System.Data.SqlClient.SqlParameter[])")] 17 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/IConfigurationData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SQLAzureMWUtils 4 | { 5 | public interface IConfigurationData 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/IMigrationOutput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLAzureMWUtils 7 | { 8 | public interface IMigrationOutput 9 | { 10 | void StatusUpdateHandler(AsyncNotificationEventArgs args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/NotificationEventFunctionCode.cs: -------------------------------------------------------------------------------- 1 | namespace SQLAzureMWUtils 2 | { 3 | public enum NotificationEventFunctionCode 4 | { 5 | // 0 = BCPUploadData, 1 = ExecuteSQLonAzure, 2 = ParseFile, 4 = , 5 = 6 | BcpUploadData = 0, 7 | ExecuteSqlOnAzure = 1, 8 | ParseFile = 2, 9 | GenerateScriptFromSQLServer = 3, 10 | AnalysisOutput = 4, 11 | SqlOutput = 5, 12 | BcpDownloadData = 6 13 | } 14 | } -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using System.Resources; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("SQLAzureMWUtils")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("SQLAzureMWUtils")] 14 | [assembly: AssemblyCopyright("Copyright © 2010")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // Setting ComVisible to false makes the types in this assembly not visible 19 | // to COM components. If you need to access a type in this assembly from 20 | // COM, set the ComVisible attribute to true on that type. 21 | [assembly: ComVisible(false)] 22 | 23 | // The following GUID is for the ID of the typelib if this project is exposed to COM 24 | [assembly: Guid("91f94e49-c9a5-4c18-8500-3d51df684fda")] 25 | 26 | // Version information for an assembly consists of the following four values: 27 | // 28 | // Major Version 29 | // Minor Version 30 | // Build Number 31 | // Revision 32 | // 33 | // You can specify all the values or you can default the Build and Revision Numbers 34 | // by using the '*' as shown below: 35 | // [assembly: AssemblyVersion("1.0.*")] 36 | [assembly: AssemblyVersion("3.9.15.0")] 37 | [assembly: AssemblyFileVersion("3.9.15.0")] 38 | [assembly: NeutralResourcesLanguageAttribute("en")] 39 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/RetryLimitExceededException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Runtime.Serialization; 6 | 7 | namespace SQLAzureMWUtils 8 | { 9 | /// 10 | /// The special type of exception that provides managed exit from a retry loop. The user code can use this 11 | /// exception to notify the retry policy that no further retry attempts are required. 12 | /// 13 | [Serializable] 14 | public sealed class RetryLimitExceededException : Exception 15 | { 16 | /// 17 | /// Initializes a new instance of the class with a default error message. 18 | /// 19 | public RetryLimitExceededException() : this(Properties.Resources.RetryLimitExceeded) 20 | { 21 | } 22 | 23 | /// 24 | /// Initializes a new instance of the class with a specified error message. 25 | /// 26 | /// The message that describes the error. 27 | public RetryLimitExceededException(string message) : base(message) 28 | { 29 | } 30 | 31 | /// 32 | /// Initializes a new instance of the class with a reference to the inner exception 33 | /// that is the cause of this exception. 34 | /// 35 | /// The exception that is the cause of the current exception. 36 | public RetryLimitExceededException(Exception innerException) : base(innerException != null ? innerException.Message : Properties.Resources.RetryLimitExceeded, innerException) 37 | { 38 | } 39 | 40 | /// 41 | /// Initializes a new instance of the class. 42 | /// 43 | /// The message that describes the error. 44 | /// The exception that is the cause of the current exception. 45 | public RetryLimitExceededException(string message, Exception innerException) : base(message, innerException) 46 | { 47 | } 48 | 49 | /// 50 | /// Initializes a new instance of the class. 51 | /// 52 | /// The that holds the serialized object data about the exception being thrown. 53 | /// The that contains contextual information about the source or destination. 54 | /// The parameter is null. 55 | /// The class name is null or is zero (0). 56 | private RetryLimitExceededException(SerializationInfo info, StreamingContext context) : base(info, context) 57 | { 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/RetryPolicy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLAzureMWUtils 7 | { 8 | public class RetryPolicy 9 | { 10 | public int RetryCount { get; set; } 11 | public TimeSpan MinimunDelay { get; set; } 12 | public TimeSpan MaximunDelay { get; set; } 13 | public TimeSpan RetryIncrementalDelay { get; set; } 14 | 15 | private RetryPolicy() 16 | { 17 | } 18 | 19 | public RetryPolicy(int retryCount, TimeSpan minimunDelay, TimeSpan maximunDelay, TimeSpan incrementalDelay) 20 | { 21 | RetryCount = retryCount; 22 | MinimunDelay = minimunDelay; 23 | MaximunDelay = maximunDelay; 24 | RetryIncrementalDelay = incrementalDelay; 25 | } 26 | 27 | public bool ShouldRetry(int retryCount, Exception lastException, out TimeSpan delay) 28 | { 29 | if (retryCount < RetryCount) 30 | { 31 | var random = new Random(); 32 | 33 | var delta = (int)((Math.Pow(2.0, retryCount) - 1.0) * random.Next((int)(RetryIncrementalDelay.TotalMilliseconds * 0.8), (int)(RetryIncrementalDelay.TotalMilliseconds * 1.2))); 34 | var interval = (int) Math.Min(checked(MinimunDelay.TotalMilliseconds + delta), MaximunDelay.TotalMilliseconds); 35 | 36 | delay = TimeSpan.FromMilliseconds(interval); 37 | 38 | return true; 39 | } 40 | 41 | delay = TimeSpan.Zero; 42 | return false; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/Returns.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Xml; 4 | 5 | namespace SQLAzureMWUtils 6 | { 7 | /// 8 | /// Summary description for Returns. 9 | /// 10 | public class DatasetResults 11 | { 12 | public DataSet DataSet { get; set; } // Resulting DataSet from SQL query 13 | public int SpReturnValue { get; set; } // Stored procedure return value (if stored procedure called) 14 | 15 | public DatasetResults() 16 | { 17 | } 18 | } 19 | 20 | public class NonQueryResults 21 | { 22 | public int ExecuteResult { get; set; } // Number of rows affected by the ExecuteNonQuery command 23 | public int SpReturnValue { get; set; } // Stored procedure return value (if stored procedure called) 24 | 25 | public NonQueryResults() 26 | { 27 | } 28 | } 29 | 30 | public class ScalarResults 31 | { 32 | public object ExecuteScalarReturnValue { get; set; } 33 | public int SpReturnValue { get; set; } // Stored procedure return value (if stored procedure called) 34 | 35 | public ScalarResults() 36 | { 37 | } 38 | } 39 | 40 | public class XmlSqlDataReader 41 | { 42 | public XmlReader XmlReader; 43 | public int SpReturnValue; // Stored procedure return value (if stored procedure called) 44 | 45 | public XmlSqlDataReader() 46 | { 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/RulesEngine/NotSupported.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Xml.Serialization; 3 | 4 | namespace SQLAzureMWUtils 5 | { 6 | /// 7 | /// 8 | /// 9 | /// Added headers, etc. 10 | /// 11 | /// 12 | 13 | public class NotSupported 14 | { 15 | private string _Text; 16 | private string _NotSubStr; 17 | private string _SearchReplace; 18 | private string _ReplaceWith; 19 | private string _WarningMessage; 20 | private bool _DisplayWarning; 21 | private bool _ReplaceString; 22 | private bool _DefaultMessage; 23 | private int _SeverityLevel; 24 | private bool _RemoveCommand; 25 | 26 | [XmlAttribute(DataType = "string", AttributeName = "Text")] 27 | public string Text 28 | { 29 | get { return _Text; } 30 | set { _Text = value; } 31 | } 32 | 33 | [XmlAttribute(DataType = "boolean", AttributeName = "ReplaceString")] 34 | public bool ReplaceString 35 | { 36 | get { return _ReplaceString; } 37 | set { _ReplaceString = value; } 38 | } 39 | 40 | [XmlAttribute(DataType = "string", AttributeName = "NotSubStr")] 41 | public string NotSubStr 42 | { 43 | get { return _NotSubStr; } 44 | set { _NotSubStr = value; } 45 | } 46 | 47 | [XmlAttribute(DataType = "int", AttributeName = "SeverityLevel")] 48 | public int SeverityLevel 49 | { 50 | get { return _SeverityLevel; } 51 | set { _SeverityLevel = value; } 52 | } 53 | 54 | [XmlAttribute(DataType = "string", AttributeName = "SearchReplace")] 55 | public string SearchReplace 56 | { 57 | get { return _SearchReplace; } 58 | set { _SearchReplace = value; } 59 | } 60 | 61 | [XmlAttribute(DataType = "string", AttributeName = "ReplaceWith")] 62 | public string ReplaceWith 63 | { 64 | get { return _ReplaceWith; } 65 | set { _ReplaceWith = value; } 66 | } 67 | 68 | [XmlAttribute(DataType = "boolean", AttributeName = "DisplayWarning")] 69 | public bool DisplayWarning 70 | { 71 | get { return _DisplayWarning; } 72 | set { _DisplayWarning = value; } 73 | } 74 | 75 | [XmlAttribute(DataType = "boolean", AttributeName = "DefaultMessage")] 76 | public bool DefaultMessage 77 | { 78 | get { return _DefaultMessage; } 79 | set { _DefaultMessage = value; } 80 | } 81 | 82 | [XmlAttribute(DataType = "string", AttributeName = "WarningMessage")] 83 | public string WarningMessage 84 | { 85 | get { return _WarningMessage; } 86 | set { _WarningMessage = value; } 87 | } 88 | 89 | [XmlAttribute(DataType = "boolean", AttributeName = "RemoveCommand")] 90 | public bool RemoveCommand 91 | { 92 | get { return _RemoveCommand; } 93 | set { _RemoveCommand = value; } 94 | } 95 | 96 | public NotSupported(string text, string replaceWith, int severityLevel, bool replaceStr, bool displayWarning, bool defaultMessage, string message, bool removeCommand) 97 | { 98 | _Text = text; 99 | _ReplaceWith = replaceWith; 100 | _SeverityLevel = severityLevel; 101 | _ReplaceString = replaceStr; 102 | _DisplayWarning = displayWarning; 103 | _DefaultMessage = defaultMessage; 104 | _WarningMessage = message; 105 | _RemoveCommand = removeCommand; 106 | } 107 | 108 | public NotSupported() 109 | { 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/RulesEngine/NotSupportedIndex.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace SQLAzureMWUtils 5 | { 6 | public class NotSupportedIndex 7 | { 8 | public NotSupportedList IndexOptions { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/RulesEngine/NotSupportedList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace SQLAzureMWUtils 5 | { 6 | public class NotSupportedList : CollectionBase 7 | { 8 | public NotSupportedList() 9 | { 10 | } 11 | 12 | public NotSupportedList(NotSupported[] arr) 13 | { 14 | AddRange(arr); 15 | } 16 | 17 | public NotSupported this[int index] 18 | { 19 | get { return (NotSupported) InnerList[index]; } 20 | } 21 | 22 | public void Add(NotSupported item) 23 | { 24 | InnerList.Add(item); 25 | } 26 | 27 | public void AddRange(NotSupported[] items) 28 | { 29 | InnerList.AddRange(items); 30 | } 31 | 32 | public void Remove(NotSupported item) 33 | { 34 | InnerList.Remove(item); 35 | } 36 | 37 | public int IndexOf(NotSupported item) 38 | { 39 | return InnerList.IndexOf(item); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/RulesEngine/NotSupportedSchema.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace SQLAzureMWUtils 5 | { 6 | public class NotSupportedSchema 7 | { 8 | public NotSupportedList SchemaChecks { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/RulesEngine/NotSupportedTable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace SQLAzureMWUtils 5 | { 6 | public class NotSupportedTable 7 | { 8 | public NotSupportedList TableStatement { get; set; } 9 | public NotSupportedList FedColumnTypes { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/RulesEngine/NotSupportedViews.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace SQLAzureMWUtils 5 | { 6 | public class NotSupportedViews 7 | { 8 | private NotSupportedList _ViewStatement; 9 | 10 | public NotSupportedList ViewStatement 11 | { 12 | get { return _ViewStatement; } 13 | set { _ViewStatement = value; } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/RulesEngine/SupportedStatement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Xml.Serialization; 4 | 5 | namespace SQLAzureMWUtils 6 | { 7 | /// 8 | /// 9 | /// 10 | /// Added headers, etc. 11 | /// 12 | /// 13 | 14 | public class SupportedStatement 15 | { 16 | private string _Text; 17 | 18 | [XmlAttribute(DataType = "string", AttributeName = "Text")] 19 | public string Text 20 | { 21 | get { return _Text; } 22 | set { _Text = value; } 23 | } 24 | 25 | public SupportedStatement(string text) 26 | { 27 | _Text = text; 28 | } 29 | 30 | public SupportedStatement() 31 | { 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/RulesEngine/SupportedStatementList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Collections; 4 | 5 | namespace SQLAzureMWUtils 6 | { 7 | public class SupportedStatementList : CollectionBase 8 | { 9 | public SupportedStatementList() 10 | { 11 | } 12 | 13 | public SupportedStatementList(SupportedStatement[] arr) 14 | { 15 | AddRange(arr); 16 | } 17 | 18 | public SupportedStatement this[int index] 19 | { 20 | get { return (SupportedStatement)InnerList[index]; } 21 | } 22 | 23 | public void Add(SupportedStatement item) 24 | { 25 | InnerList.Add(item); 26 | } 27 | 28 | public void AddRange(SupportedStatement[] items) 29 | { 30 | InnerList.AddRange(items); 31 | } 32 | 33 | public void Remove(SupportedStatement item) 34 | { 35 | InnerList.Remove(item); 36 | } 37 | 38 | public int IndexOf(SupportedStatement item) 39 | { 40 | return InnerList.IndexOf(item); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/ServerTypes.cs: -------------------------------------------------------------------------------- 1 | namespace SQLAzureMWUtils 2 | { 3 | public enum ServerTypes 4 | { 5 | SQLAzure = 0, 6 | SQLAzureFed = 1, 7 | SQLServer = 2 8 | } 9 | } -------------------------------------------------------------------------------- /Lesson02/SQLAzureMigration-master/SQLAzureMWUtils/TargetServerInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace SQLAzureMWUtils 7 | { 8 | public class TargetServerInfo 9 | { 10 | public ServerTypes ServerType { get; set; } 11 | public string ServerInstance { get; set; } 12 | public string Login { get; set; } 13 | public string Password { get; set; } 14 | public string RootDatabase { get; set; } 15 | public string TargetDatabase { get; set; } 16 | public bool LoginSecure { get; set; } 17 | 18 | public TargetServerInfo() 19 | { 20 | ServerInstance = ""; 21 | Login = ""; 22 | Password = ""; 23 | RootDatabase = ""; 24 | TargetDatabase = ""; 25 | LoginSecure = false; 26 | } 27 | 28 | public string ConnectionStringRootDatabase 29 | { 30 | get 31 | { 32 | return CommonFunc.GetConnectionString(ServerInstance, LoginSecure, RootDatabase, Login, Password); 33 | } 34 | } 35 | 36 | public string ConnectionStringTargetDatabase 37 | { 38 | get 39 | { 40 | return CommonFunc.GetConnectionString(ServerInstance, LoginSecure, TargetDatabase, Login, Password); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Lesson02/ScaleUpAzureSQLDB.ps1: -------------------------------------------------------------------------------- 1 | ## Code is reviewed and is in working condition 2 | 3 | param( 4 | [Parameter(Mandatory=$true)] 5 | [string]$resourcegroupname, 6 | [Parameter(Mandatory=$true)] 7 | [string]$azuresqlservername, 8 | [Parameter(Mandatory=$true)] 9 | [string]$databasename, 10 | [Parameter(Mandatory=$true)] 11 | [string]$newservicetier, 12 | [Parameter(Mandatory=$true)] 13 | [string]$servicetierperfomancelevel, 14 | [Parameter(Mandatory=$true)] 15 | [string]$AzureProfileFilePath 16 | 17 | ) 18 | 19 | 20 | 21 | Try 22 | { 23 | Write-Host "Login to your Azure Account" -ForegroundColor Yellow 24 | 25 | # log the execution of the script 26 | Start-Transcript -Path .\log\ScaleUpAzureSQLDB.txt -Append 27 | 28 | # Set AzureProfileFilePath relative to the script directory if it's not provided as parameter 29 | if([string]::IsNullOrEmpty($AzureProfileFilePath)) 30 | { 31 | $AzureProfileFilePath="..\MyAzureProfile.json" 32 | } 33 | 34 | #Login to Azure Account 35 | if((Test-Path -Path $AzureProfileFilePath)) 36 | { 37 | #If Azure profile file is available get the profile information from the file 38 | $profile = Import-AzureRmContext -Path $AzureProfileFilePath 39 | #retrieve the subscription id from the profile. 40 | $SubscriptionID = $profile.Context.Subscription.SubscriptionId 41 | } 42 | else 43 | { 44 | Write-Host "File Not Found $AzureProfileFilePath" -ForegroundColor Yellow 45 | 46 | # If the Azure Profile file isn't available, login using the dialog box. 47 | # Provide your Azure Credentials in the login dialog box 48 | $profile = Login-AzureRmAccount 49 | $SubscriptionID = $profile.Context.Subscription.SubscriptionId 50 | } 51 | 52 | #Set the Azure Context 53 | Set-AzureRmContext -SubscriptionId $SubscriptionID | Out-Null 54 | 55 | Write-Host "Modifying Service Tier to $newservicetier..." -ForegroundColor Yellow 56 | 57 | Set-AzureRmSqlDatabase -ResourceGroupName $resourcegroupname -ServerName $azuresqlservername ` 58 | -DatabaseName $databasename -Edition $newservicetier ` 59 | -RequestedServiceObjectiveName $servicetierperfomancelevel 60 | 61 | 62 | } 63 | catch 64 | { 65 | $ErrorMessage = $_.Exception.Message 66 | $FailedItem = $_.Exception.ItemName 67 | Write-host $ErrorMessage $FailedItem -ForegroundColor Red 68 | } 69 | 70 | 71 | -------------------------------------------------------------------------------- /Lesson02/VerifyMigration.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | SELECT TOP (1000) [OrderID] 4 | ,[CustomerID] 5 | ,[SalespersonPersonID] 6 | ,[PickedByPersonID] 7 | ,[ContactPersonID] 8 | ,[BackorderOrderID] 9 | ,[OrderDate] 10 | ,[ExpectedDeliveryDate] 11 | ,[CustomerPurchaseOrderNumber] 12 | ,[IsUndersupplyBackordered] 13 | ,[Comments] 14 | ,[DeliveryInstructions] 15 | ,[InternalComments] 16 | ,[PickingCompletedWhen] 17 | ,[LastEditedBy] 18 | ,[LastEditedWhen] 19 | FROM [toystore].[Sales].[Orders] -------------------------------------------------------------------------------- /Lesson02/toystore.bak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson02/toystore.bak -------------------------------------------------------------------------------- /Lesson03/BackupAzureSQLDBToAzureStorage.ps1: -------------------------------------------------------------------------------- 1 | ## Code is reviewed and is in working condition 2 | 3 | #Export Azure SQL Database bacpac to Azure Storage 4 | #.\BackupAzureSQLDBToAzureStorage.ps1 -storageaccountname "toyfactorystorage" -resourcegroupname "toystore" -container "backups" -sqlserver toyfactory -database "toystore" -sqluser "sqladmin" -sqlpassword "Packt@pub2" 5 | param( 6 | [string]$storageaccountname, 7 | [string]$resourcegroupname, 8 | [string]$sqlserver, 9 | [string]$container, 10 | [string]$database, 11 | [string]$sqluser, 12 | [string]$sqlpassword 13 | ) 14 | 15 | #Login to Azure account 16 | Login-AzureRmAccount 17 | 18 | if([string]::IsNullOrEmpty($storageaccountname) -eq $true) 19 | { 20 | Write-Host "Provide a valid Storage Account Name" -ForegroundColor Red 21 | return 22 | } 23 | if([string]::IsNullOrEmpty($resourcegroupname) -eq $true) 24 | { 25 | Write-Host "Provide a valid resource group" -ForegroundColor Red 26 | return 27 | } 28 | if([string]::IsNullOrEmpty($container) -eq $true) 29 | { 30 | Write-Host "Provide a valid Storage Container Name" -ForegroundColor Red 31 | return 32 | } 33 | 34 | # create bacpac file name 35 | $bacpacFilename = $database + "_"+(Get-Date).ToString("ddMMyyyymm") + ".bacpac" 36 | 37 | 38 | # set the current storage account 39 | $storageaccountkey = Get-AzureRmStorageAccountKey -ResourceGroupName $resourcegroupname -Name $storageaccountname 40 | # set the default storage account 41 | Set-AzureRmCurrentStorageAccount -StorageAccountName $storageaccountname -ResourceGroupName $resourcegroupname | Out-Null 42 | 43 | # set the bacpac location 44 | $bloblocation = "https://$storageaccountname.blob.core.windows.net/$container/$bacpacFilename" 45 | 46 | #set the credential 47 | $securesqlpassword = ConvertTo-SecureString -String $sqlpassword -AsPlainText -Force 48 | $credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $sqluser, $securesqlpassword 49 | 50 | 51 | Write-Host "Exporting $database to $bloblocation..." -ForegroundColor Green 52 | 53 | $export = New-AzureRmSqlDatabaseExport -ResourceGroupName $resourcegroupname -ServerName $sqlserver.Split('.')[0] -DatabaseName $database -StorageUri $bloblocation -AdministratorLogin $credentials.UserName -AdministratorLoginPassword $credentials.Password -StorageKeyType StorageAccessKey -StorageKey $storageaccountkey.Value[0].Tostring() 54 | 55 | 56 | #Write-Host $export -ForegroundColor Green 57 | 58 | 59 | # Check status of the export 60 | While(1 -eq 1) 61 | { 62 | $exportstatus = Get-AzureRmSqlDatabaseImportExportStatus -OperationStatusLink $export.OperationStatusLink 63 | if($exportstatus.Status -eq "Succeeded") 64 | { 65 | Write-Host $exportstatus.StatusMessage -ForegroundColor Green 66 | return 67 | } 68 | If($exportstatus.Status -eq "InProgress") 69 | { 70 | Write-Host $exportstatus.StatusMessage -ForegroundColor Green 71 | Start-Sleep -Seconds 5 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Lesson03/toystore.bacpac: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson03/toystore.bacpac -------------------------------------------------------------------------------- /Lesson03/toystore.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson03/toystore.zip -------------------------------------------------------------------------------- /Lesson04/GeoRestoreAzureSQLDB.ps1: -------------------------------------------------------------------------------- 1 | ## Code is reviewed and is in working condition 2 | 3 | param( 4 | [Parameter(Mandatory=$true)] 5 | [string]$sqlserver, 6 | [Parameter(Mandatory=$true)] 7 | [string]$database, 8 | [Parameter(Mandatory=$true)] 9 | [string]$sqluser, 10 | [Parameter(Mandatory=$true)] 11 | [string]$sqlpassword, 12 | [Parameter(Mandatory=$true)] 13 | [string]$resourcegroupname, 14 | [string]$newdatabasename 15 | ) 16 | 17 | #Login to Azure subscription 18 | 19 | Login-AzureRmAccount 20 | 21 | 22 | # get the geo database backup to restore 23 | 24 | $geodb = Get-AzureRmSqlDatabaseGeoBackup -ServerName $sqlserver -DatabaseName $database -ResourceGroupName $resourcegroupname 25 | 26 | #Display Geo-Database properties 27 | $geodb | Out-Host 28 | 29 | #get the database name from the geodb object 30 | $geodtabasename = $geodb.DatabaseName.ToString() 31 | 32 | #set the new database name 33 | if([string]::IsNullOrEmpty($newdatabasename)) 34 | { 35 | $newdatabasename = $database + (Get-Date).ToString("MMddyyyymm") 36 | } 37 | 38 | Write-Host "Restoring database $geodtabasename from geo backup" -ForegroundColor Green 39 | 40 | # perform the geo restore 41 | $restore = Restore-AzureRmSqlDatabase -FromGeoBackup -ResourceGroupName $resourcegroupname -ResourceId $geodb.ResourceID -ServerName $sqlserver -TargetDatabaseName $newdatabasename -Edition "Standard" -ServiceObjectiveName "S2" 42 | 43 | if($rerror -ne $null) 44 | { 45 | Write-Host $rerror -ForegroundColor red; 46 | } 47 | 48 | if($restore -ne $null) 49 | { 50 | $restoredb = $restore.DatabaseName.ToString() 51 | Write-Host "Database $database restored from Geo Backup as database $restoredb" -ForegroundColor Green 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Lesson04/InsertNewColor.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | -- Insert a new color 4 | INSERT INTO [Warehouse].[Colors] 5 | SELECT 6 | 37 AS ColorID 7 | ,'Dark Yellow' AS ColorName 8 | ,1 AS LastEditedBy 9 | ,GETUTCDATE() AS ValidFrom 10 | ,'9999-12-31 23:59:59.9999999' As Validto 11 | GO 12 | -- Verify the insert 13 | SELECT [ColorID] 14 | ,[ColorName] 15 | ,[LastEditedBy] 16 | ,[ValidFrom] 17 | ,[ValidTo] 18 | FROM [Warehouse].[Colors] 19 | WHERE ColorID=37 20 | -------------------------------------------------------------------------------- /Lesson04/PITRAzureSQLDB.ps1: -------------------------------------------------------------------------------- 1 | ## Code is reviewed and is in working condition 2 | 3 | param( 4 | [Parameter(Mandatory=$true)] 5 | [string]$sqlserver, 6 | [Parameter(Mandatory=$true)] 7 | [string]$database, 8 | [Parameter(Mandatory=$true)] 9 | [string]$sqluser, 10 | [Parameter(Mandatory=$true)] 11 | [string]$sqlpassword, 12 | [Parameter(Mandatory=$true)] 13 | [string]$resourcegroupname, 14 | [string]$newdatabasename 15 | ) 16 | 17 | # Login to Azure subscription 18 | Login-AzureRmAccount 19 | 20 | # list the earliest restore point 21 | # Ask user for the point in time the database is to be restored 22 | 23 | While (1) 24 | { 25 | #Retrieve the distinct restore points from which a SQL Database can be restored 26 | $restoredetails = Get-AzureRmSqlDatabaseRestorePoints -ServerName $sqlserver -DatabaseName $database -ResourceGroupName $resourcegroupname 27 | #get the earliest restore date 28 | $erd=$restoredetails.EarliestRestoreDate.ToString(); 29 | #ask for the point in time the database is to be restored 30 | $restoretime = Read-Host "The earliest restore time is $erd.`n Enter a restore time between Earlist restore time and current time." 31 | #convert the input to datatime data type 32 | $restoretime = $restoretime -as [DateTime] 33 | #if restore time isn't a valid data, prompt for a valid date 34 | if(!$restoretime) 35 | { 36 | Write-Host "Enter a valid date" -ForegroundColor Red 37 | }else 38 | { 39 | #end the while loop if restore date is a valid date 40 | break; 41 | } 42 | } 43 | 44 | #set the new database name 45 | if([string]::IsNullOrEmpty($newdatabasename)) 46 | { 47 | $newdatabasename = $database + (Get-Date).ToString("MMddyyyymm") 48 | } 49 | 50 | # get the original database object 51 | $db = Get-AzureRmSqlDatabase -DatabaseName $database -ServerName $sqlserver -ResourceGroupName $resourcegroupname 52 | 53 | Write-Host "Restoring Database $database as of $newdatabasename to the time $restoretime" 54 | 55 | #restore the database to point in time 56 | $restore = Restore-AzureRmSqlDatabase -FromPointInTimeBackup -PointInTime $restoretime -ResourceId $db.ResourceId -ServerName $db.ServerName -TargetDatabaseName $newdatabasename -Edition $db.Edition -ServiceObjectiveName $db.CurrentServiceObjectiveName -ResourceGroupName $db.ResourceGroupName 57 | 58 | 59 | # restore deleted database 60 | 61 | 62 | if($rerror -ne $null) 63 | { 64 | Write-Host $rerror -ForegroundColor red; 65 | } 66 | if($restore -ne $null) 67 | { 68 | Write-Host "Database $newdatabasename restored Successfully"; 69 | } 70 | -------------------------------------------------------------------------------- /Lesson05/Activity A-1.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | /* 4 | Activity A - 1 5 | Scenario: 6 | Let’s say that we have two customers Mike and John and two database users each for our two customers. (Created in previous exercise). 7 | You have to implement Row Level Security so each customer should only be able to view and edit their records. 8 | The user CustomerAdmin is allowed to view and edit all customer records. 9 | */ 10 | 11 | 12 | -- Create Customer table and populate with dummy data 13 | CREATE TABLE Customers 14 | ( 15 | CustomerID int identity, 16 | Name sysname, 17 | CreditCardNumber varchar(100), 18 | Phone varchar(100), 19 | Email varchar(100) 20 | ) 21 | Go 22 | INSERT INTO Customers VALUES 23 | ('Mike',0987654312345678,9876543210,'mike@outlook.com'), 24 | ('Mike',0987654356784567,9876549870,'mike1@outlook.com'), 25 | ('Mike',0984567431234567,9876567210,'mike2@outlook.com'), 26 | ('John@dataplatformlabs.com',0987654312345678,9876246210,'john@outlook.com'), 27 | ('John@dataplatformlabs.com',0987654123784567,9876656870,'john2@outlook.com'), 28 | ('John@dataplatformlabs.com',09856787431234567,9876467210,'john3@outlook.com'), 29 | ('CustomerAdmin',0987654312235578,9873456210,'john@outlook.com'), 30 | ('CustomerAdmin',0984564123784567,9872436870,'mike2@outlook.com'), 31 | ('CustomerAdmin',0945677874312367,9872427210,'chris3@outlook.com') 32 | 33 | -- Create a contained database user without login 34 | CREATE USER CustomerAdmin WITHOUT LOGIN 35 | 36 | -- Grant read access to Customers table to Mike, John and CustomerAdmin 37 | GRANT SELECT ON dbo.Customers TO Mike 38 | GO 39 | GRANT SELECT ON dbo.Customers TO [john@aadityarama26gmail.onmicrosoft.com] 40 | GO 41 | GRANT SELECT ON dbo.Customers TO CustomerAdmin 42 | 43 | -- Create security predicate to filter out the rows based on the logged in user 44 | CREATE SCHEMA Security; 45 | GO 46 | CREATE FUNCTION Security.fn_securitypredicate(@Customer AS sysname) 47 | RETURNS TABLE 48 | WITH SCHEMABINDING 49 | AS 50 | RETURN SELECT 1 AS predicateresult 51 | WHERE @Customer = USER_NAME() OR USER_NAME() = 'CustomerAdmin'; 52 | 53 | GO 54 | 55 | -- Create and apply the security profile 56 | CREATE SECURITY POLICY CustomerFilter 57 | ADD FILTER PREDICATE Security.fn_securitypredicate(Name) 58 | ON dbo.Customers, 59 | ADD BLOCK PREDICATE Security.fn_securitypredicate(Name) 60 | ON dbo.Customers AFTER INSERT 61 | WITH (STATE = ON); 62 | 63 | -- What Mike sees!!! 64 | 65 | EXECUTE AS USER='Mike' 66 | GO 67 | SELECT USER_NAME() 68 | GO 69 | SELECT * FROM dbo.Customers 70 | 71 | -- What Mike can update!!! 72 | EXECUTE AS USER='Mike' 73 | GO 74 | SELECT USER_NAME() 75 | GO 76 | -- CustomerID 11 belongs to John 77 | UPDATE dbo.Customers SET Email='MikeBlue@outlook.com' WHERE 78 | CustomerID=11 79 | GO 80 | -- Switch User context to John 81 | EXECUTE AS USER='john@aadityarama26gmail.onmicrosoft.com' 82 | GO 83 | SELECT USER_NAME() 84 | GO 85 | -- Verify if email is updated or not 86 | SELECT * FROM dbo.Customers WHERE CustomerID=11 87 | 88 | -- What Mike can insert!!! 89 | 90 | EXECUTE AS USER='Mike' 91 | GO 92 | SELECT USER_NAME() 93 | GO 94 | INSERT INTO dbo.Customers 95 | VALUES('john@aadityarama26gmail.onmicrosoft.com',9876543445345678,65412396852,'Mike@dataplatformlabs.com') 96 | 97 | -- What CustomerAdmin sees!!! 98 | REVERT; 99 | GO 100 | EXECUTE AS USER='CustomerAdmin' 101 | GO 102 | SELECT USER_NAME() 103 | GO 104 | SELECT * FROM dbo.Customers 105 | 106 | 107 | -- Switch off the security policy 108 | ALTER SECURITY POLICY CustomerFilter 109 | WITH (STATE = OFF); 110 | -------------------------------------------------------------------------------- /Lesson05/Activity A-2.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | /* 4 | Activity A-2 5 | Scenario: In the previous activity we learn to use Row Level Security to limit access to authorized rows to specific users. However, if a user has access to the set of rows he can still see all the column values. 6 | In this activity, we’ll implement Dynamic Data Masking to mask the credit card number, phone number and email of a customer from the users. 7 | */ 8 | -- Create a new user and grant read access on Customers table 9 | CREATE USER TestUser WITHOUT LOGIN; 10 | GO 11 | GRANT SELECT ON dbo.Customers TO TestUser 12 | 13 | -- Mask the CreditCardNumber, phone and email column 14 | ALTER TABLE dbo.Customers ALTER COLUMN Phone 15 | VARCHAR(100) MASKED WITH (FUNCTION = 'default()') 16 | GO 17 | ALTER TABLE dbo.Customers ALTER COLUMN Email 18 | VARCHAR(100) MASKED WITH (FUNCTION = 'email()') 19 | GO 20 | ALTER TABLE dbo.Customers ALTER COLUMN CreditCardNumber 21 | VARCHAR(100) MASKED WITH (FUNCTION = 'partial(0,"XXX-XX-",4)') 22 | 23 | -- What Test user sees!!! 24 | EXECUTE AS USER='TestUser' 25 | GO 26 | SELECT * FROM dbo.Customers; 27 | 28 | -- List out the masked columns 29 | REVERT; 30 | GO 31 | SELECT mc.name, t.name as table_name,mc.masking_function 32 | FROM sys.masked_columns AS mc 33 | JOIN sys.tables AS t 34 | ON mc.[object_id] = t.[object_id] 35 | WHERE is_masked = 1 36 | and t.name='Customers' 37 | 38 | -- Allow test user to see masked data 39 | GRANT UNMASK TO TestUser; 40 | GO 41 | EXECUTE AS USER='TestUser' 42 | GO 43 | SELECT * FROM dbo.Customers; 44 | GO 45 | 46 | -- Revoke Unmask access. Test user now sees masked data 47 | REVERT; 48 | REVOKE UNMASK TO TestUSER 49 | 50 | -------------------------------------------------------------------------------- /Lesson05/AdvancedThreatProtection/BruteForceAttack/BruteForceAttack.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson05/AdvancedThreatProtection/BruteForceAttack/BruteForceAttack.exe -------------------------------------------------------------------------------- /Lesson05/AdvancedThreatProtection/BruteForceAttack/BruteForceAttack.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Lesson05/AdvancedThreatProtection/SQLInjection/SQLInjection.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson05/AdvancedThreatProtection/SQLInjection/SQLInjection.exe -------------------------------------------------------------------------------- /Lesson05/AdvancedThreatProtection/SQLInjection/SQLInjection.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lesson05/BruteForceAttack/.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /Lesson05/BruteForceAttack/BruteForceAttack.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BruteForceAttack", "BruteForceAttack\BruteForceAttack.csproj", "{81C22BFA-4974-437A-A8B2-199F9C32822B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {81C22BFA-4974-437A-A8B2-199F9C32822B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {81C22BFA-4974-437A-A8B2-199F9C32822B}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {81C22BFA-4974-437A-A8B2-199F9C32822B}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {81C22BFA-4974-437A-A8B2-199F9C32822B}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Lesson05/BruteForceAttack/BruteForceAttack/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Lesson05/BruteForceAttack/BruteForceAttack/BruteForceAttack.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {81C22BFA-4974-437A-A8B2-199F9C32822B} 8 | Exe 9 | Properties 10 | BruteForceAttack 11 | BruteForceAttack 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 60 | -------------------------------------------------------------------------------- /Lesson05/BruteForceAttack/BruteForceAttack/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data.SqlClient; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Configuration; 8 | 9 | namespace BruteForceAttack 10 | { 11 | class Program 12 | { 13 | static void Main(string[] args) 14 | { 15 | for (int i = 1; i < 10000; i++) 16 | { 17 | try 18 | { 19 | string _server = ConfigurationSettings.AppSettings["Server"].ToString(); 20 | string _database = ConfigurationSettings.AppSettings["database"].ToString(); 21 | string _user = RandomString(5); 22 | string _password = RandomString(10); 23 | string _Constr = "Server=tcp:" + _server + ".database.windows.net;Database=" + _database +";User ID =" +_user + "@packtdbserver;Password="+ _password + ";Trusted_Connection=False;Encrypt=True;"; 24 | Console.WriteLine(_Constr); 25 | SqlConnection _con = new SqlConnection(_Constr); 26 | _con.Open(); 27 | } 28 | 29 | 30 | catch 31 | { 32 | //Do nothing 33 | } 34 | } 35 | 36 | } 37 | 38 | private static Random random = new Random(); 39 | private static string RandomString(int length) 40 | { 41 | const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 42 | return new string(Enumerable.Repeat(chars, length) 43 | .Select(s => s[random.Next(s.Length)]).ToArray()); 44 | } 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Lesson05/BruteForceAttack/BruteForceAttack/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BruteForceAttack")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BruteForceAttack")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("81c22bfa-4974-437a-a8b2-199f9c32822b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Lesson05/Exercise_ContainedDatabaseUsers.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | -- Exercise: Creating contained database users for Azure AD authentication. 4 | -- Execute in toystore database 5 | 6 | --Create a contained database user (SQL Authentication) 7 | CREATE USER Mike WITH PASSWORD='John@pwd' 8 | GO 9 | -- Make Mike toystore database ownner 10 | ALTER ROLE db_owner ADD MEMBER Mike 11 | 12 | 13 | --Create a contained database user (Azure AD Authentication) 14 | CREATE USER [John@dataplatformlabs.com] FROM EXTERNAL PROVIDER 15 | 16 | -- Give read access to John on all tables 17 | ALTER ROLE db_datareader ADD Member [John@dataplatformlabs.com] 18 | -------------------------------------------------------------------------------- /Lesson05/Exercise_DatabaseLevelFirewallRules.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | -- Exercise: Managing Database Level Firewall rules from Transact SQL. 4 | -- can be executed in master or any user database 5 | 6 | -- list out existing database level firewall rule 7 | SELECT * FROM sys.database_firewall_rules 8 | GO 9 | 10 | -- Add a new database level firewall rule 11 | Exec sp_set_database_firewall_rule @name=N'MasterDB', 12 | @start_ip_address='115.118.10.0', 13 | @end_ip_address='115.118.16.255' 14 | 15 | -- list out existing database level firewall rule 16 | SELECT * FROM sys.database_firewall_rules 17 | GO 18 | 19 | -- Update an existing database level firewall rule 20 | Exec sp_set_database_firewall_rule 21 | @name=N'MasterDB', 22 | @start_ip_address='115.118.1.0', 23 | @end_ip_address='115.118.16.255' 24 | 25 | -- list out existing database level firewall rule 26 | SELECT * FROM sys.database_firewall_rules 27 | GO 28 | 29 | -- Delete an existing database level firewall rule 30 | Exec sp_delete_database_firewall_rule @name=N'MasterDB' 31 | GO 32 | 33 | -- list out existing database level firewall rule 34 | SELECT * FROM sys.database_firewall_rules 35 | GO -------------------------------------------------------------------------------- /Lesson05/Exercise_ServerLevelFirewallRules.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | -- Exercise: Managing Server Level Firewall rules from Transact SQL 3 | -- Run in Master database 4 | 5 | -- List out all existing Server firewall rules 6 | Select * from sys.firewall_rules 7 | GO 8 | 9 | -- Add a new server level firewall rule 10 | -- Server level firewall rule are added to Master database 11 | Execute sp_set_firewall_rule @name = N'Work', 12 | @start_ip_address = '115.118.1.0', 13 | @end_ip_address = '115.118.16.255' 14 | GO 15 | -- List out all existing Server firewall rules 16 | Select * from sys.firewall_rules 17 | 18 | GO 19 | -- Update the firewall rule with new IP 20 | Execute sp_set_firewall_rule @name = N'Work', 21 | @start_ip_address = '115.118.10.0', 22 | @end_ip_address = '115.118.16.255' 23 | 24 | -- List out all existing Server firewall rules 25 | Select * from sys.firewall_rules 26 | 27 | GO 28 | 29 | -- Delete an existing firewall rule 30 | Execute sp_delete_firewall_rule @name= N'Work' 31 | 32 | -- List out all existing Server firewall rules 33 | Select * from sys.firewall_rules 34 | 35 | 36 | -------------------------------------------------------------------------------- /Lesson05/SQLInjection/.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /Lesson05/SQLInjection/SQLInjection.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQLInjection", "SQLInjection\SQLInjection.csproj", "{C084852F-FC84-4A54-9983-28043BA5D257}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C084852F-FC84-4A54-9983-28043BA5D257}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C084852F-FC84-4A54-9983-28043BA5D257}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C084852F-FC84-4A54-9983-28043BA5D257}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C084852F-FC84-4A54-9983-28043BA5D257}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Lesson05/SQLInjection/SQLInjection/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Lesson05/SQLInjection/SQLInjection/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace SampleApplication 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new SQLInjection()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lesson05/SQLInjection/SQLInjection/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SampleApplication")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SampleApplication")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c084852f-fc84-4a54-9983-28043ba5d257")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Lesson05/SQLInjection/SQLInjection/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SampleApplication.Properties 12 | { 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SampleApplication.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Lesson05/SQLInjection/SQLInjection/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SampleApplication.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Lesson05/SQLInjection/SQLInjection/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lesson05/SQLInjection/SQLInjection/SQLInjection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | using System.Data.Sql; 11 | using System.Data.SqlClient; 12 | using System.Configuration; 13 | 14 | namespace SampleApplication 15 | { 16 | public partial class SQLInjection : Form 17 | { 18 | public SQLInjection() 19 | { 20 | InitializeComponent(); 21 | } 22 | 23 | private void btnSearch_Click(object sender, EventArgs e) 24 | { 25 | string _SupplierName = txtSupplierName.Text; 26 | string _SupplierID = txtSupplierID.Text; 27 | string _server = ConfigurationSettings.AppSettings["server"].ToString(); 28 | string _user = ConfigurationSettings.AppSettings["user"].ToString(); 29 | string _database = ConfigurationSettings.AppSettings["database"].ToString(); 30 | string _password = ConfigurationSettings.AppSettings["password"].ToString(); 31 | string _Constr = "Server=tcp:" + _server + ".database.windows.net;Database=" + _database +";User ID =" + _user + "@" + _server +";Password=" + _password +";Trusted_Connection=False;Encrypt=True;"; 32 | SqlConnection _con = new SqlConnection(_Constr); 33 | 34 | string _query = "select * from users where username = '" + _SupplierName + "' and usersecret = '" + _SupplierID + "'"; 35 | 36 | _con.Open(); 37 | 38 | SqlDataAdapter _sqlda = new SqlDataAdapter(_query, _con); 39 | DataSet ds = new DataSet(); 40 | _sqlda.Fill(ds); 41 | dgvSupplier.DataSource = ds.Tables[0]; 42 | 43 | 44 | 45 | 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Lesson06/Certificate/toyfactory.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson06/Certificate/toyfactory.cer -------------------------------------------------------------------------------- /Lesson06/Certificate/toyfactory.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson06/Certificate/toyfactory.pfx -------------------------------------------------------------------------------- /Lesson06/Certificate/toyfactory.pvk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson06/Certificate/toyfactory.pvk -------------------------------------------------------------------------------- /Lesson06/Elastic DB tool scripts/GetMappings.ps1: -------------------------------------------------------------------------------- 1 | ## Code is reviewed and is in working condition 2 | 3 | <# 4 | /******************************************************** 5 | * * 6 | * © Microsoft. All rights reserved. * 7 | * * 8 | *********************************************************/ 9 | 10 | .SYNOPSIS 11 | For a given Sharding setup, this script outputs the Mapping 12 | of the shards. 13 | 14 | .NOTES 15 | Author: Microsoft SQL Elastic Scale team 16 | Last Updated: 7/30/2015 17 | 18 | .EXAMPLES 19 | .\GetMappings.ps1 ` 20 | -UserName 'mysqluser' ` 21 | -Password 'MySqlPassw0rd' ` 22 | -ShardMapManagerServerName 'abcdefghij.database.windows.net' ` 23 | -ShardMapManagerDatabaseName 'MyShardMapManagerDB' 24 | -ShardMapName 'CustomerIdShardMap' 25 | 26 | #> 27 | 28 | param ( 29 | [parameter(Mandatory=$true)][string]$UserName, 30 | [parameter(Mandatory=$true)][string]$Password, 31 | [parameter(Mandatory=$true)][string]$ShardMapManagerServerName, 32 | [parameter(Mandatory=$true)][string]$ShardMapManagerDatabaseName, 33 | [parameter(Mandatory=$true)][string]$ShardMapName 34 | ) 35 | 36 | Set-StrictMode -Version Latest 37 | $ErrorActionPreference = "Stop" 38 | 39 | # Import modules 40 | $ScriptDir = Split-Path -parent $MyInvocation.MyCommand.Path 41 | Import-Module $ScriptDir\ShardManagement -Force 42 | 43 | # Create new (or replace existing) shard map manager 44 | $ShardMapManager = Get-ShardMapManager -UserName $UserName -Password $Password -SqlServerName $ShardMapManagerServerName -SqlDatabaseName $ShardMapManagerDatabaseName 45 | 46 | $ShardMap = $ShardMapManager.GetShardMap($ShardMapName); 47 | 48 | # Get shard map 49 | If ($ShardMap.MapType.Equals([Microsoft.Azure.SqlDatabase.ElasticScale.ShardManagement.ShardMapType]::List)) 50 | { 51 | $ShardMap = Get-ListShardMap -KeyType $ShardMap.KeyType.ToString() -ShardMapManager $ShardMapManager -ListShardMapName $ShardMapName 52 | } 53 | ElseIf ($ShardMap.MapType.Equals([Microsoft.Azure.SqlDatabase.ElasticScale.ShardManagement.ShardMapType]::Range)) 54 | { 55 | $ShardMap = Get-RangeShardMap -KeyType $ShardMap.KeyType.ToString() -ShardMapManager $ShardMapManager -RangeShardMapName $ShardMapName 56 | } 57 | Else 58 | { 59 | Write-Error "Invalid Shard Map Type" 60 | } 61 | 62 | # Get mappings 63 | return Get-Mappings -ShardMap $ShardMap | Format-List 64 | 65 | -------------------------------------------------------------------------------- /Lesson06/Elastic DB tool scripts/GetShards.ps1: -------------------------------------------------------------------------------- 1 | ## Code is reviewed and is in working condition 2 | 3 | <# 4 | /******************************************************** 5 | * * 6 | * © Microsoft. All rights reserved. * 7 | * * 8 | *********************************************************/ 9 | 10 | .SYNOPSIS 11 | For a given Sharding setup, this script outputs the list of Shards. 12 | 13 | .NOTES 14 | Author: Microsoft SQL Elastic Scale team 15 | Last Updated: 8/13/2015 16 | 17 | .EXAMPLES 18 | .\GetShards.ps1 ` 19 | -UserName 'mysqluser' ` 20 | -Password 'MySqlPassw0rd' ` 21 | -ShardMapManagerServerName 'abcdefghij.database.windows.net' ` 22 | -ShardMapManagerDatabaseName 'MyShardMapManagerDB' 23 | -ShardMapName 'CustomerIdShardMap' 24 | 25 | #> 26 | 27 | param ( 28 | [parameter(Mandatory=$true)][string]$UserName, 29 | [parameter(Mandatory=$true)][string]$Password, 30 | [parameter(Mandatory=$true)][string]$ShardMapManagerServerName, 31 | [parameter(Mandatory=$true)][string]$ShardMapManagerDatabaseName, 32 | [parameter(Mandatory=$true)][string]$ShardMapName 33 | ) 34 | 35 | Set-StrictMode -Version Latest 36 | $ErrorActionPreference = "Stop" 37 | 38 | # Import modules 39 | $ScriptDir = Split-Path -parent $MyInvocation.MyCommand.Path 40 | Import-Module $ScriptDir\ShardManagement -Force 41 | 42 | # Create new (or replace existing) shard map manager 43 | $ShardMapManager = Get-ShardMapManager -UserName $UserName -Password $Password -SqlServerName $ShardMapManagerServerName -SqlDatabaseName $ShardMapManagerDatabaseName 44 | 45 | $ShardMap = $ShardMapManager.GetShardMap($ShardMapName) 46 | 47 | # Get mappings 48 | return Get-Shards -ShardMap $ShardMap | Format-List 49 | 50 | -------------------------------------------------------------------------------- /Lesson06/Elastic DB tool scripts/ShardManagement/Microsoft.Azure.SqlDatabase.ElasticScale.Client.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson06/Elastic DB tool scripts/ShardManagement/Microsoft.Azure.SqlDatabase.ElasticScale.Client.dll -------------------------------------------------------------------------------- /Lesson06/Elastic DB tool scripts/ShardManagement/Microsoft.Azure.SqlDatabase.ElasticScale.Client/Microsoft.Azure.SqlDatabase.ElasticScale.Client.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson06/Elastic DB tool scripts/ShardManagement/Microsoft.Azure.SqlDatabase.ElasticScale.Client/Microsoft.Azure.SqlDatabase.ElasticScale.Client.nupkg -------------------------------------------------------------------------------- /Lesson06/Elastic DB tool scripts/ShardManagement/Microsoft.Azure.SqlDatabase.ElasticScale.Client/lib/net45/Microsoft.Azure.SqlDatabase.ElasticScale.Client.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson06/Elastic DB tool scripts/ShardManagement/Microsoft.Azure.SqlDatabase.ElasticScale.Client/lib/net45/Microsoft.Azure.SqlDatabase.ElasticScale.Client.dll -------------------------------------------------------------------------------- /Lesson06/Elastic DB tool scripts/ShardManagement/nuget.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson06/Elastic DB tool scripts/ShardManagement/nuget.exe -------------------------------------------------------------------------------- /Lesson06/Elastic DB tool scripts/Upgrade.ps1: -------------------------------------------------------------------------------- 1 | ## Code is reviewed and is in working condition 2 | 3 | <# 4 | /********************************************************* 5 | * * 6 | * © Microsoft. All rights reserved. * 7 | * * 8 | *********************************************************/ 9 | 10 | .SYNOPSIS 11 | Upgrades a Shard Map Manager and all its shards to the current version. 12 | 13 | .NOTES 14 | Author: Microsoft SQL Elastic Scale team 15 | Last Updated: 9/5/2014 16 | #> 17 | param( 18 | [Parameter(Mandatory = $true)] 19 | [string] 20 | $ShardMapManagerServerName="", 21 | [Parameter(Mandatory = $true)] 22 | [string] 23 | $ShardMapManagerDatabaseName="", 24 | [Parameter(Mandatory = $true)] 25 | [string] 26 | $UserName="", 27 | [Parameter(Mandatory = $true)] 28 | [string] 29 | $Password="" 30 | ) 31 | 32 | Set-StrictMode -Version Latest 33 | $ErrorActionPreference = "Stop" 34 | 35 | # Import modules 36 | $ScriptDir = Split-Path -parent $MyInvocation.MyCommand.Path 37 | Import-Module $ScriptDir\ShardManagement -Force 38 | 39 | # Get Shard Map Manager 40 | 41 | $SmmConnectionString = New-Object System.Data.SqlClient.SqlConnectionStringBuilder("Server=$ShardMapManagerServerName; Initial Catalog=$ShardMapManagerDatabaseName; User ID=$UserName; Password=$Password;") 42 | $LoadPolicy = [Microsoft.Azure.SqlDatabase.ElasticScale.ShardManagement.ShardMapManagerLoadPolicy]::Lazy 43 | 44 | $smm = [Microsoft.Azure.SqlDatabase.ElasticScale.ShardManagement.ShardMapManagerFactory]::GetSqlShardMapManager($SmmConnectionString, $LoadPolicy) 45 | 46 | # Upgrade GSM 47 | Write-Host "Upgrading GSM" 48 | $smm.UpgradeGlobalStore(); 49 | 50 | # Get distinct locations in this shard map manager 51 | $Locations = $smm.GetDistinctShardLocations(); 52 | 53 | # Upgrade all shards 54 | foreach ($Location in $Locations) 55 | { 56 | Write-Host "Upgrading " $Location.ToString() 57 | $smm.UpgradeLocalStore($Location); 58 | } 59 | -------------------------------------------------------------------------------- /Lesson06/ElasticQueries.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | -- Create Master Key 4 | CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Packt@pub2'; 5 | GO 6 | -- Create database scoped credentials 7 | CREATE DATABASE SCOPED CREDENTIAL toystore_creds1 WITH IDENTITY = 'sqadmin', 8 | SECRET = 'Packt@pub2' 9 | GO 10 | -- Create external data source 11 | CREATE EXTERNAL DATA SOURCE toystore_dsrc 12 | WITH 13 | ( 14 | TYPE=SHARD_MAP_MANAGER, 15 | LOCATION='toyfactory.database.windows.net', 16 | DATABASE_NAME='toystore_SMM', 17 | CREDENTIAL= toystore_creds, 18 | SHARD_MAP_NAME='toystorerangemap' 19 | ); 20 | 21 | 22 | -- Create the external table 23 | CREATE EXTERNAL TABLE [dbo].[Customers]( 24 | [CustomerID] [int] NOT NULL, 25 | [CustomerName] [nvarchar](100) NOT NULL, 26 | [BillToCustomerID] [int] NOT NULL, 27 | [CustomerCategoryID] [int] NOT NULL, 28 | [BuyingGroupID] [int] NULL, 29 | [PrimaryContactPersonID] [int] NOT NULL, 30 | [AlternateContactPersonID] [int] NULL, 31 | [DeliveryMethodID] [int] NOT NULL, 32 | [DeliveryCityID] [int] NOT NULL, 33 | [PostalCityID] [int] NOT NULL, 34 | [CreditLimit] [decimal](18, 2) NULL, 35 | [AccountOpenedDate] [date] NOT NULL, 36 | [StandardDiscountPercentage] [decimal](18, 3) NOT NULL, 37 | [IsStatementSent] [bit] NOT NULL, 38 | [IsOnCreditHold] [bit] NOT NULL, 39 | [PaymentDays] [int] NOT NULL, 40 | [PhoneNumber] [nvarchar](20) NOT NULL, 41 | [FaxNumber] [nvarchar](20) NOT NULL, 42 | [DeliveryRun] [nvarchar](5) NULL, 43 | [RunPosition] [nvarchar](5) NULL, 44 | [WebsiteURL] [nvarchar](256) NOT NULL, 45 | [DeliveryAddressLine1] [nvarchar](60) NOT NULL, 46 | [DeliveryAddressLine2] [nvarchar](60) NULL, 47 | [DeliveryPostalCode] [nvarchar](10) NOT NULL, 48 | [DeliveryLocation] [varchar](1) NOT NULL, 49 | [PostalAddressLine1] [nvarchar](60) NOT NULL, 50 | [PostalAddressLine2] [nvarchar](60) NULL, 51 | [PostalPostalCode] [nvarchar](10) NOT NULL, 52 | [LastEditedBy] [int] NOT NULL, 53 | [ValidFrom] [datetime2](7) NOT NULL, 54 | [ValidTo] [datetime2](7) NOT NULL 55 | ) WITH 56 | ( 57 | DATA_SOURCE = toystore_dsrc, 58 | SCHEMA_NAME = 'Sales', 59 | OBJECT_NAME = 'Customers', 60 | DISTRIBUTION=SHARDED(customerid) 61 | ); 62 | 63 | -- query the dbo.customers table 64 | SELECT * FROM dbo.Customers 65 | 66 | -- Create external orders table 67 | CREATE EXTERNAL TABLE [dbo].[Orders]( 68 | [OrderID] [int] NOT NULL, 69 | [CustomerID] [int] NOT NULL, 70 | [SalespersonPersonID] [int] NOT NULL, 71 | [PickedByPersonID] [int] NULL, 72 | [ContactPersonID] [int] NOT NULL, 73 | [BackorderOrderID] [int] NULL, 74 | [OrderDate] [date] NOT NULL, 75 | [ExpectedDeliveryDate] [date] NOT NULL, 76 | [CustomerPurchaseOrderNumber] [nvarchar](20) NULL, 77 | [IsUndersupplyBackordered] [bit] NOT NULL, 78 | [Comments] [nvarchar](max) NULL, 79 | [DeliveryInstructions] [nvarchar](max) NULL, 80 | [InternalComments] [nvarchar](max) NULL, 81 | [PickingCompletedWhen] [smalldatetime] NULL, 82 | [LastEditedBy] [int] NOT NULL, 83 | [LastEditedWhen] [smalldatetime] NOT NULL 84 | ) WITH 85 | ( 86 | DATA_SOURCE = toystore_dsrc, 87 | SCHEMA_NAME = 'Sales', 88 | OBJECT_NAME = 'Orders', 89 | DISTRIBUTION=SHARDED(customerid) 90 | ); 91 | 92 | 93 | Select * from dbo.Orders so join dbo.Customers sc 94 | on so.customerid = sc.customerid 95 | 96 | -- Get existing External Data sources 97 | SELECT * FROM sys.external_data_sources; 98 | -- Get existing External Tables 99 | SELECT * FROM sys.external_tables -------------------------------------------------------------------------------- /Lesson06/Executions.txt: -------------------------------------------------------------------------------- 1 | .\Sharding.ps1 -ResourceGroup toystore -SqlServer toyfactory -UserName sqladmin -Password Packt@pub2 -ShardMapManagerDatabase toystore_SMM -DatabaseToShard toystore 2 | 3 | 4 | .\SplitToyStoreShard.ps1 -ResourceGroup toystore -SqlServer toyfactory -UserName sqladmin -Password Packt@pub2 -SplitMergeDatabase toystore_splitmerge -SplitMergeServiceEndpoint "https://splitmerge.cloudapp.net/" -ShardMapManagerDatabaseName toystore_SMM -Shard2 toystore_Shard_200 -ShardMapName toystorerangemap -SplitRangeLow 0 -SplitRangeHigh 200 -SplitValue 100 5 | 6 | 7 | 8 | .\shard-toystore.ps1 -ResourceGroup toystore -SqlServer toyfactory -UserName sqladmin -Password Packt@pub2 -ShardMapManagerDatabase toystore_SMM -DatabaseToShard toystore -AzureProfileFilePath C:\Code\MyAzureProfile.json 9 | 10 | 11 | .\toystore-Add-Shards.ps1 -ResourceGroup toystore -SqlServer toyfactory -UserName sqladmin -Password Packt@pub2 -ShardMapManagerDatabase toystore_SMM -DatabaseToShard toystore -AzureProfileFilePath C:\Code\MyAzureProfile.json 12 | 13 | 14 | # split 50 records to the newly created toystore_Shard_50_100 15 | .\toystore_split_4shards.ps1 -ResourceGroup toystore -SqlServer toyfactory -UserName sqladmin -Password Packt@pub2 -SplitMergeDatabase toystore_splitmerge -SplitMergeServiceEndpoint "https://splitmerge.cloudapp.net/" -ShardMapManagerDatabaseName toystore_SMM -Shard2 toystore_Shard_50_100 -ShardMapName toystorerangemap -SplitRangeLow 1 -SplitRangeHigh 1000 -SplitValue 50 16 | 17 | # split 50 records to the newly created toystore_Shard_150_200 18 | .\toystore_split_4shards.ps1 -ResourceGroup toystore -SqlServer toyfactory -UserName sqladmin -Password Packt@pub2 -SplitMergeDatabase toystore_splitmerge -SplitMergeServiceEndpoint "https://splitmerge.cloudapp.net/" -ShardMapManagerDatabaseName toystore_SMM -Shard2 toystore_Shard_150_200 -ShardMapName toystorerangemap -SplitRangeLow 1 -SplitRangeHigh 1000 -SplitValue 150 19 | -------------------------------------------------------------------------------- /Lesson06/Sharding/TableScripts/1_CreateSchemas.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | IF NOT EXISTS(Select 1 from sys.schemas where name='Application') 4 | BEGIN 5 | EXEC sp_executesql N'CREATE SCHEMA [Application]' 6 | END 7 | GO 8 | IF NOT EXISTS(Select 1 from sys.schemas where name='Sales') 9 | BEGIN 10 | EXEC sp_executesql N'CREATE SCHEMA [Sales]' 11 | END 12 | -------------------------------------------------------------------------------- /Lesson06/Sharding/TableScripts/2_Application.Countries.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | /****** Object: Table [Application].[Countries] Script Date: 12/22/2017 4:36:55 PM ******/ 4 | SET ANSI_NULLS ON 5 | GO 6 | 7 | SET QUOTED_IDENTIFIER ON 8 | GO 9 | IF OBJECT_ID('Application.Countries') IS NULL 10 | BEGIN 11 | CREATE TABLE [Application].[Countries]( 12 | [CountryID] [int] NOT NULL, 13 | [CountryName] [nvarchar](60) NOT NULL, 14 | [FormalName] [nvarchar](60) NOT NULL, 15 | [IsoAlpha3Code] [nvarchar](3) NULL, 16 | [IsoNumericCode] [int] NULL, 17 | [CountryType] [nvarchar](20) NULL, 18 | [LatestRecordedPopulation] [bigint] NULL, 19 | [Continent] [nvarchar](30) NOT NULL, 20 | [Region] [nvarchar](30) NOT NULL, 21 | [Subregion] [nvarchar](30) NOT NULL, 22 | [Border] [geography] NULL, 23 | [LastEditedBy] [int] NOT NULL, 24 | [ValidFrom] [datetime2](7) NOT NULL, 25 | [ValidTo] [datetime2](7) NOT NULL, 26 | CONSTRAINT [PK_Application_Countries] PRIMARY KEY CLUSTERED 27 | ( 28 | [CountryID] ASC 29 | )WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY], 30 | CONSTRAINT [UQ_Application_Countries_CountryName] UNIQUE NONCLUSTERED 31 | ( 32 | [CountryName] ASC 33 | )WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY], 34 | CONSTRAINT [UQ_Application_Countries_FormalName] UNIQUE NONCLUSTERED 35 | ( 36 | [FormalName] ASC 37 | )WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY] 38 | ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] 39 | 40 | END 41 | ELSE 42 | BEGIN 43 | PRINT 'There is already an object named Countries in the database' 44 | END 45 | 46 | -------------------------------------------------------------------------------- /Lesson06/Sharding/TableScripts/3_Sales.Customer.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | /****** Object: Table [Sales].[Customers] Script Date: 12/22/2017 4:37:30 PM ******/ 4 | SET ANSI_NULLS ON 5 | GO 6 | 7 | SET QUOTED_IDENTIFIER ON 8 | GO 9 | IF OBJECT_ID('Sales.Customers') IS NULL 10 | BEGIN 11 | CREATE TABLE [Sales].[Customers]( 12 | [CustomerID] [int] NOT NULL, 13 | [CustomerName] [nvarchar](100) NOT NULL, 14 | [BillToCustomerID] [int] NOT NULL, 15 | [CustomerCategoryID] [int] NOT NULL, 16 | [BuyingGroupID] [int] NULL, 17 | [PrimaryContactPersonID] [int] NOT NULL, 18 | [AlternateContactPersonID] [int] NULL, 19 | [DeliveryMethodID] [int] NOT NULL, 20 | [DeliveryCityID] [int] NOT NULL, 21 | [PostalCityID] [int] NOT NULL, 22 | [CreditLimit] [decimal](18, 2) NULL, 23 | [AccountOpenedDate] [date] NOT NULL, 24 | [StandardDiscountPercentage] [decimal](18, 3) NOT NULL, 25 | [IsStatementSent] [bit] NOT NULL, 26 | [IsOnCreditHold] [bit] NOT NULL, 27 | [PaymentDays] [int] NOT NULL, 28 | [PhoneNumber] [nvarchar](20) NOT NULL, 29 | [FaxNumber] [nvarchar](20) NOT NULL, 30 | [DeliveryRun] [nvarchar](5) NULL, 31 | [RunPosition] [nvarchar](5) NULL, 32 | [WebsiteURL] [nvarchar](256) NOT NULL, 33 | [DeliveryAddressLine1] [nvarchar](60) NOT NULL, 34 | [DeliveryAddressLine2] [nvarchar](60) NULL, 35 | [DeliveryPostalCode] [nvarchar](10) NOT NULL, 36 | [DeliveryLocation] [varchar](1) NOT NULL, 37 | [PostalAddressLine1] [nvarchar](60) NOT NULL, 38 | [PostalAddressLine2] [nvarchar](60) NULL, 39 | [PostalPostalCode] [nvarchar](10) NOT NULL, 40 | [LastEditedBy] [int] NOT NULL, 41 | [ValidFrom] [datetime2](7) NOT NULL, 42 | [ValidTo] [datetime2](7) NOT NULL 43 | ) ON [PRIMARY] 44 | END 45 | ELSE 46 | BEGIN 47 | PRINT 'There is already an object named Customers in the database' 48 | END 49 | 50 | -------------------------------------------------------------------------------- /Lesson06/Sharding/TableScripts/4_Sales.Orders.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | /****** Object: Table [Sales].[Orders] Script Date: 12/22/2017 4:40:30 PM ******/ 4 | SET ANSI_NULLS ON 5 | GO 6 | 7 | SET QUOTED_IDENTIFIER ON 8 | GO 9 | IF OBJECT_ID('Sales.Orders') IS NULL 10 | BEGIN 11 | CREATE TABLE [Sales].[Orders]( 12 | [OrderID] [int] NOT NULL, 13 | [CustomerID] [int] NOT NULL, 14 | [SalespersonPersonID] [int] NOT NULL, 15 | [PickedByPersonID] [int] NULL, 16 | [ContactPersonID] [int] NOT NULL, 17 | [BackorderOrderID] [int] NULL, 18 | [OrderDate] [date] NOT NULL, 19 | [ExpectedDeliveryDate] [date] NOT NULL, 20 | [CustomerPurchaseOrderNumber] [nvarchar](20) NULL, 21 | [IsUndersupplyBackordered] [bit] NOT NULL, 22 | [Comments] [nvarchar](max) NULL, 23 | [DeliveryInstructions] [nvarchar](max) NULL, 24 | [InternalComments] [nvarchar](max) NULL, 25 | [PickingCompletedWhen] [smalldatetime] NULL, 26 | [LastEditedBy] [int] NOT NULL, 27 | [LastEditedWhen] [smalldatetime] NOT NULL 28 | ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] 29 | END 30 | ELSE 31 | BEGIN 32 | PRINT 'There is already an object named Orders in the database' 33 | END 34 | -------------------------------------------------------------------------------- /Lesson06/Splitting/Certificate/toyfactory.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson06/Splitting/Certificate/toyfactory.cer -------------------------------------------------------------------------------- /Lesson06/Splitting/Certificate/toyfactory.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson06/Splitting/Certificate/toyfactory.pfx -------------------------------------------------------------------------------- /Lesson06/Splitting/Certificate/toyfactory.pvk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson06/Splitting/Certificate/toyfactory.pvk -------------------------------------------------------------------------------- /Lesson06/Splitting/SplitMergeLibraries/EnterpriseLibrary.TransientFaultHandling.6.0.1304.0/EnterpriseLibrary.TransientFaultHandling.6.0.1304.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson06/Splitting/SplitMergeLibraries/EnterpriseLibrary.TransientFaultHandling.6.0.1304.0/EnterpriseLibrary.TransientFaultHandling.6.0.1304.0.nupkg -------------------------------------------------------------------------------- /Lesson06/Splitting/SplitToyStoreShard.ps1: -------------------------------------------------------------------------------- 1 | ## Code is reviewed and is in working condition 2 | 3 | param 4 | ( 5 | [parameter(Mandatory=$true)] 6 | [String] $ResourceGroup, 7 | [parameter(Mandatory=$true)] 8 | [String] $SqlServer, 9 | [parameter(Mandatory=$true)] 10 | [String] $UserName, 11 | [parameter(Mandatory=$true)] 12 | [String] $Password, 13 | [parameter(Mandatory=$true)] 14 | [String] $SplitMergeDatabase, 15 | [String] $AzureProfileFilePath, 16 | [parameter(Mandatory=$true)] 17 | [String] $SplitMergeServiceEndpoint, 18 | [parameter(Mandatory=$true)] 19 | [String] $ShardMapManagerDatabaseName, 20 | [parameter(Mandatory=$true)] 21 | [String] $Shard2, 22 | [parameter(Mandatory=$true)] 23 | [String] $ShardMapName, 24 | [parameter(Mandatory=$true)] 25 | [String] $SplitRangeLow, 26 | [parameter(Mandatory=$true)] 27 | [String] $SplitRangeHigh, 28 | [parameter(Mandatory=$true)] 29 | [String] $SplitValue, 30 | [bool] $CreateSplitMergeDatabase = $false 31 | 32 | ) 33 | 34 | Start-Transcript -Path "$ScriptPath\Log\SplitToyStoreShard.txt" -Append 35 | 36 | $CertificateThumbprint = $null 37 | 38 | $ScriptPath = split-path -parent $MyInvocation.MyCommand.Definition 39 | 40 | $AzureProfileFilePath = "..\..\MyAzureProfile.json" 41 | 42 | #Login to Azure Account 43 | if((Test-Path -Path $AzureProfileFilePath)) 44 | { 45 | $profile = Import-AzureRmContext -Path $AzureProfileFilePath 46 | $SubscriptionID = $profile.Context.Subscription.SubscriptionId 47 | } 48 | else 49 | { 50 | Write-Host "File Not Found $AzureProfileFilePath" -ForegroundColor Red 51 | 52 | # Provide your Azure Credentials in the login dialog box 53 | $profile = Login-AzureRmAccount 54 | $SubscriptionID = $profile.Context.Subscription.SubscriptionId 55 | } 56 | 57 | #Set the Azure Context 58 | Set-AzureRmContext -SubscriptionId $SubscriptionID | Out-Null 59 | 60 | # create the split-merge database. 61 | # if you have already deployed the web service this step isn't requied. 62 | 63 | if($CreateSplitMergeDatabase) 64 | { 65 | #Create a database to store split merge status 66 | $command = "..\..\Lesson01\ProvisionAzureSQLDatabase.ps1\ProvisionAzureSQLDatabase.ps1 -ResourceGroup $ResourceGroup -SQLServer $SqlServer -UserName $UserName -Password $Password -SQLDatabase $SplitMergeDatabase -Edition Basic" 67 | Invoke-Expression -Command $command 68 | Exit; 69 | 70 | } 71 | 72 | 73 | # Import SplitMerge module 74 | $ScriptDir = Split-Path -parent $MyInvocation.MyCommand.Path 75 | Import-Module $ScriptDir\SplitMerge -Force 76 | 77 | 78 | Write-Output 'Sending split request' 79 | $splitOperationId = Submit-SplitRequest ` 80 | -SplitMergeServiceEndpoint $SplitMergeServiceEndpoint ` 81 | -ShardMapManagerServerName "$SqlServer.database.windows.net" ` 82 | -ShardMapManagerDatabaseName $ShardMapManagerDatabaseName ` 83 | -TargetServerName "$SqlServer.database.windows.net" ` 84 | -TargetDatabaseName $Shard2 ` 85 | -UserName $UserName ` 86 | -Password $Password ` 87 | -ShardMapName $ShardMapName ` 88 | -ShardKeyType 'Int32' ` 89 | -SplitRangeLowKey $SplitRangeLow ` 90 | -SplitValue $SplitValue ` 91 | -SplitRangeHighKey $SplitRangeHigh ` 92 | -CertificateThumbprint $CertificateThumbprint 93 | 94 | 95 | # Get split request output 96 | Wait-SplitMergeRequest -SplitMergeServiceEndpoint $SplitMergeServiceEndpoint -OperationId $splitOperationId -CertificateThumbprint $CertificateThumbprint 97 | 98 | 99 | -------------------------------------------------------------------------------- /Lesson06/Splitting/nuget.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson06/Splitting/nuget.exe -------------------------------------------------------------------------------- /Lesson06/VerticalScaling/Start-Workload.ps1: -------------------------------------------------------------------------------- 1 | ## Code is reviewed and is in working condition 2 | 3 | param 4 | ( 5 | [Parameter(Mandatory=$true)] 6 | [string]$sqlserver, 7 | [Parameter(Mandatory=$true)] 8 | [string]$database, 9 | [Parameter(Mandatory=$true)] 10 | [string]$sqluser, 11 | [Parameter(Mandatory=$true)] 12 | [string]$sqlpassword, 13 | [Parameter(Mandatory=$false)] 14 | [string]$ostresspath="C:\Program Files\Microsoft Corporation\RMLUtils\ostress.exe", 15 | [Parameter(Mandatory=$false)] 16 | [string]$workloadsql="C:\Code\Lesson6\workload.sql" 17 | 18 | ) 19 | 20 | #$query = "SELECT a.* FROM sys.objects a, sys.objects b,sys.objects c,sys.objects d,sys.objects e,sys.objects f,sys.objects g,sys.objects h" 21 | $sqlserver = $sqlserver + ".database.windows.net" 22 | 23 | $arguments = "-S$sqlserver -U$sqluser -P$sqlpassword -d$database -i$workloadsql -n25 -r30 -q" 24 | $arguments 25 | Start-Process -FilePath $ostresspath -ArgumentList $arguments -RedirectStandardOutput workloadoutput.txt -RedirectStandardError workloaderror.txt -NoNewWindow -PassThru -Wait -------------------------------------------------------------------------------- /Lesson06/VerticalScaling/workload.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | SELECT a.* 4 | FROM 5 | sys.objects a, 6 | sys.objects b, 7 | sys.objects c, 8 | sys.objects d, 9 | sys.objects e, 10 | sys.objects f, 11 | sys.objects g, 12 | sys.objects h -------------------------------------------------------------------------------- /Lesson06/certificate.txt: -------------------------------------------------------------------------------- 1 | makecert ^ 2 | -n "CN=*.cloudapp.net" ^ 3 | -r -cy end -sky exchange -eku "1.3.6.1.5.5.7.3.1,1.3.6.1.5.5.7.3.2" ^ 4 | -a sha1 -len 2048 ^ 5 | -sr currentuser -ss root ^ 6 | -sv toyfactory.pvk toyfactory.cer 7 | 8 | 9 | pvk2pfx -pvk toyfactory.pvk -spc toyfactory.cer -pfx toyfactory.pfx -pi Awesome@1234 10 | 11 | B042D8608A996409757D43B4AE63EC92DB22F25C -------------------------------------------------------------------------------- /Lesson07/ElasticDatabaseJob.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson07/ElasticDatabaseJob.sql -------------------------------------------------------------------------------- /Lesson07/Execution.txt: -------------------------------------------------------------------------------- 1 | # Remove an elastic pool 2 | .\Manage-ElasticPool.ps1 -ResourceGroup toystore -SqlServer toyfactory -UserName sqladmin -Password Packt@pub2 -ElasticPoolName toyfactorypool -Operation Remove -AzureProfileFilePath C:\Code\MyAzureProfile.json 3 | 4 | # Create an elastic pool 5 | .\Manage-ElasticPool.ps1 -ResourceGroup toystore -SqlServer toyfactory -UserName sqladmin -Password Packt@pub2 -ElasticPoolName toyfactorypool -ElasticPoolEdition Standard -eDTU 100 -MaxeDTU 100 -MineDTU 10 -AzureProfileFilePath C:\Code\MyAzureProfile.json -Operation Create -DatabasesToAdd "toystore_Shard_1_50,toystore_Shard_50_100,toystore_Shard_100_150,toystore_Shard_150_200" -------------------------------------------------------------------------------- /Lesson08/ActiveGeoReplication/Executions.txt: -------------------------------------------------------------------------------- 1 | # Replicate toystore_Shard_1_50 and toystore_Shard_50_100 2 | .\Manage-ActiveGeoReplication.ps1 -ResourceGroup toystore -PrimarySqlServer toyfactory -UserName sqladmin -Password Packt@pub2 -SecondarySqlServer toyfactory-centralus -SecondaryServerLocation "Central US" -DatabasesToReplicate "toystore_Shard_1_50,toystore_Shard_50_100" -Operation "Add" -AzureProfileFilePath C:\Code\MyAzureProfile.json 3 | 4 | # failover to the secondary server 5 | .\Manage-ActiveGeoReplication.ps1 -ResourceGroup toystore -PrimarySqlServer toyfactory -UserName sqladmin -Password Packt@pub2 -SecondarySqlServer toyfactory-centralus -SecondaryServerLocation "Central US" -DatabasesToReplicate "toystore_Shard_1_50,toystore_Shard_50_100" -failover $true -AzureProfileFilePath C:\Code\MyAzureProfile.json -------------------------------------------------------------------------------- /Lesson08/Activity_AcceleratedDatabaseRecovery.sql: -------------------------------------------------------------------------------- 1 | 2 | 3 | -- Run the queries from 1-3 on database with and without Accelerated Database Recovery turned on 4 | -- The script is to compare the transaction rollback speed with and without Accelerated Database Recovery turned on 5 | 6 | -- Step 1: Check ADR is off or on 7 | SELECT 8 | [Name], 9 | is_accelerated_database_recovery_on 10 | FROM sys.databases 11 | WHERE [Name]='toystore' 12 | 13 | 14 | 15 | -- Step 2: Create orders table and insert records in the table. 16 | -- Observe that the begin transaction does not have a corresponding commit transaction 17 | 18 | CREATE TABLE Orders 19 | ( 20 | OrderId INT IDENTITY, 21 | Quantity INT, 22 | Amount MONEY, 23 | OrderDate DATETIME2 24 | ) 25 | GO 26 | BEGIN TRANSACTION 27 | DECLARE @i INT=1 28 | 29 | WHILE (@i <= 10000000) 30 | BEGIN 31 | INSERT INTO Orders VALUES(@i*2,@i*0.5,DATEADD(MINUTE,@i,GETDATE())) 32 | Set @i = @i + 1 33 | END 34 | 35 | -- Step 3. Execut the below query to cancel kill session in which query in step 2 is running and record the 36 | -- estimated time remaining to rollback the transaction 37 | 38 | KILL 112 39 | GO 40 | KILL 112 with statusonly 41 | GO 42 | SELECT session_id,status from sys.dm_exec_requests where session_id=112 43 | 44 | -- Repeat Steps 1 - 3 for database with ADR enabled. -------------------------------------------------------------------------------- /Lesson08/Execution.txt: -------------------------------------------------------------------------------- 1 | # Remove an elastic pool 2 | .\Manage-ElasticPool.ps1 -ResourceGroup toystore -SqlServer toyfactory -UserName sqladmin -Password Packt@pub2 -ElasticPoolName toyfactorypool -Operation Remove -AzureProfileFilePath C:\Code\MyAzureProfile.json 3 | 4 | # Create an elastic pool 5 | .\Manage-ElasticPool.ps1 -ResourceGroup toystore -SqlServer toyfactory -UserName sqladmin -Password Packt@pub2 -ElasticPoolName toyfactorypool -ElasticPoolEdition Standard -eDTU 100 -MaxeDTU 100 -MineDTU 10 -AzureProfileFilePath C:\Code\MyAzureProfile.json -Operation Create -DatabasesToAdd "toystore_Shard_1_50,toystore_Shard_50_100,toystore_Shard_100_150,toystore_Shard_150_200" -------------------------------------------------------------------------------- /Lesson09/CreateExtendedEvent.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | -- Create Extended Event to record queries greater than 10 seconds 4 | CREATE EVENT SESSION [LongRunningQueries] ON DATABASE 5 | ADD EVENT sqlserver.sql_statement_completed 6 | ( 7 | ACTION 8 | ( 9 | sqlserver.database_name, 10 | sqlserver.query_hash, 11 | sqlserver.query_plan_hash, 12 | sqlserver.sql_text, 13 | sqlserver.username 14 | ) 15 | WHERE ([sqlserver].[database_name]=N'toystore') 16 | ) 17 | ADD TARGET package0.ring_buffer 18 | WITH (STARTUP_STATE=OFF) 19 | GO 20 | 21 | -- Start the Event Session 22 | ALTER EVENT SESSION [LongRunningQueries] 23 | ON DATABASE 24 | STATE = START; 25 | 26 | -- Stop the Event Session 27 | ALTER EVENT SESSION [LongRunningQueries] 28 | ON DATABASE 29 | STATE = STOP; 30 | 31 | -- Drop the Event Target 32 | ALTER EVENT SESSION [LongRunningQueries] 33 | ON DATABASE 34 | DROP TARGET package0.ring_buffer; 35 | GO 36 | -- Drop the Event Session 37 | DROP EVENT SESSION [LongRunningQueries] 38 | ON DATABASE; 39 | GO 40 | 41 | -------------------------------------------------------------------------------- /Lesson09/InMemoryOLTP/Cleanup.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | -- Clean up 4 | DROP PROCEDURE IF EXISTS uspInsertOrders_Inmem 5 | GO 6 | DROP PROCEDURE IF EXISTS uspInsertOrders 7 | GO 8 | DROP TABLE IF EXISTS [Sales].Orders_Inmem 9 | GO 10 | DROP TABLE IF EXISTS [Sales].Customers_Inmem 11 | GO 12 | -- delete inserted data from the orders table. 13 | DELETE FROM sales.orders WHERE orderdate=CONVERT(date, getdate()) 14 | GO 15 | -- Change the database edition to basic 16 | ALTER DATABASE toystore 17 | MODIFY (EDITION = 'basic'); -------------------------------------------------------------------------------- /Lesson09/InMemoryOLTP/Execute.txt: -------------------------------------------------------------------------------- 1 | Change service tier to Premium 2 | 3 | PowerShell.exe "C:\Code\Lesson02\ScaleUpAzureSQLDB.ps1 -resourcegroupname toystore -azuresqlservername toyfactory -databasename toystore -newservicetier Premium -servicetierperfomancelevel P1 -AzureProfileFilePath C:\Code\MyAzureProfile.json" 4 | 5 | Disk Based Workload 6 | 7 | .\Start-Workload.ps1 -sqlserver toyfactory -database toystore -sqluser sqladmin -sqlpassword Packt@pub2 -ostresspath "C:\Program Files\Microsoft Corporation\RMLUtils\ostress.exe" -workloadtype disk 8 | 9 | In-Memory Workload 10 | 11 | .\Start-Workload.ps1 -sqlserver toyfactory -database toystore -sqluser sqladmin -sqlpassword Packt@pub2 -ostresspath "C:\Program Files\Microsoft Corporation\RMLUtils\ostress.exe" -workloadtype inmem -------------------------------------------------------------------------------- /Lesson09/InMemoryOLTP/Start-Workload.ps1: -------------------------------------------------------------------------------- 1 | ## Code is reviewed and is in working condition 2 | 3 | param 4 | ( 5 | [Parameter(Mandatory=$true)] 6 | [string]$sqlserver, 7 | [Parameter(Mandatory=$true)] 8 | [string]$database, 9 | [Parameter(Mandatory=$true)] 10 | [string]$sqluser, 11 | [Parameter(Mandatory=$true)] 12 | [string]$sqlpassword, 13 | [Parameter(Mandatory=$false)] 14 | [string]$ostresspath="C:\Program Files\Microsoft Corporation\RMLUtils\ostress.exe", 15 | [string] $workloadtype, # disk/Inmem 16 | [int]$numberoforderstoinsert=10 17 | 18 | 19 | ) 20 | 21 | If($workloadtype -eq "inmem") 22 | { 23 | $query = "Execute uspInsertOrders_Inmem @numberoforderstoinsert=$numberoforderstoinsert" 24 | 25 | } 26 | elseif($workloadtype -eq "disk") 27 | { 28 | $query = "Execute uspInsertOrders @numberoforderstoinsert=$numberoforderstoinsert" 29 | 30 | }else 31 | { 32 | Write-Host "Invalid workload type $workloadtype" 33 | break; 34 | } 35 | 36 | $sqlserver = $sqlserver + ".database.windows.net" 37 | 38 | $arguments = "-S$sqlserver -U$sqluser -P$sqlpassword -d$database -Q`"$query`" -n100 -r100" 39 | 40 | $arguments 41 | 42 | $sw = [Diagnostics.Stopwatch]::StartNew() 43 | 44 | Start-Process -FilePath $ostresspath -ArgumentList $arguments -RedirectStandardOutput workloadoutput.txt -RedirectStandardError workloaderror.txt -NoNewWindow -PassThru -Wait 45 | 46 | $sw.Stop() 47 | Write-Host "`n Elapsed Time (Seconds): " $sw.Elapsed.TotalSeconds -ForegroundColor Green 48 | 49 | Read-Host "Press a key to exit!!!" -------------------------------------------------------------------------------- /Lesson09/IntelligentInsights/Blocking1.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [string]$server="packtdbserver2.database.windows.net", 4 | [string]$database="toystore_ADR", 5 | [string]$user="dbadmin", 6 | [string]$password="Awesome@1234" 7 | ) 8 | 9 | # Query to simulate high log IO and increase Disk size (Resource limit alert) 10 | $query1=" 11 | begin tran 12 | update Application.People set FullName='Kevin Doe' WHERE PersonID=2 13 | " 14 | Write-Host $query1 15 | $s = New-PSSession 16 | Invoke-Sqlcmd -ServerInstance $server -Database $database -Username $user -Password $password -Query $query1 -QueryTimeout 0 17 | Pop-Location 18 | 19 | 20 | -------------------------------------------------------------------------------- /Lesson09/IntelligentInsights/Blocking2.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [string]$server="packtdbserver2.database.windows.net", 4 | [string]$database="toystore_ADR", 5 | [string]$user="dbadmin", 6 | [string]$password="Awesome@1234" 7 | ) 8 | 9 | 10 | $query2=" 11 | begin tran 12 | update Application.People set FullName='Ram Doe' WHERE PersonID=2 13 | 14 | update Application.People set IsPermittedToLogOn=0 WHERE PersonID=2 15 | " 16 | Write-Host $query2 17 | Invoke-Sqlcmd -ServerInstance $server -Database $database -Username $user -Password $password -Query $query2 -QueryTimeout 0 18 | pop-location 19 | 20 | 21 | -------------------------------------------------------------------------------- /Lesson09/IntelligentInsights/Blocking3.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [string]$server="packtdbserver2.database.windows.net", 4 | [string]$database="toystore_ADR", 5 | [string]$user="dbadmin", 6 | [string]$password="Awesome@1234" 7 | ) 8 | 9 | 10 | 11 | 12 | $query3=" 13 | begin tran 14 | update Application.People set FullName='John Doe' WHERE PersonID=2 15 | 16 | update Application.People set IsPermittedToLogOn=0 WHERE PersonID=2 17 | " 18 | Write-Host $query3 19 | Invoke-Sqlcmd -ServerInstance $server -Database $database -Username $user -Password $password -Query $query3 -QueryTimeout 0 20 | pop-location 21 | -------------------------------------------------------------------------------- /Lesson09/IntelligentInsights/HighIO1.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [string]$server="packtdbserver.database.windows.net", 4 | [string]$database="toystore", 5 | [string]$user="dbadmin", 6 | [string]$password="Awesome@1234" 7 | ) 8 | 9 | 10 | # Query to simulate high log IO and increase Disk size (Resource limit alert) 11 | $query="DROP TABLE IF EXISTS t1; 12 | GO 13 | CREATE TABLE t1 (Sno INT IDENTITY,col1 CHAR(8000)); 14 | GO 15 | INSERT INTO t1 VALUES ('dummy') 16 | GO 100000" 17 | 18 | Invoke-Sqlcmd -ServerInstance $server -Database $database -Username $user -Password $password -Query $query -AbortOnError 19 | 20 | pop-location -------------------------------------------------------------------------------- /Lesson09/IntelligentInsights/HighIO_Timeouts.ps1: -------------------------------------------------------------------------------- 1 | param 2 | ( 3 | [string]$server="packtdbserver2.database.windows.net", 4 | [string]$database="toystore_ADR", 5 | [string]$user="dbadmin", 6 | [string]$password="Awesome@1234" 7 | ) 8 | 9 | 10 | # Query to simulate high log IO and increase Disk size (Resource limit alert) 11 | $query=" 12 | DROP TABLE IF EXISTS t2; 13 | SELECT a.* INTO t2 FROM sys.objects a, sys.objects b, sys.objects c, sys.objects d, sys.objects e;" 14 | $i=1; 15 | #timeouts 16 | While($i -le 100) 17 | { 18 | 19 | Invoke-Sqlcmd -ServerInstance $server -Database $database -Username $user -Password $password -Query $query -ErrorAction SilentlyContinue 20 | Write-Output "Iteration $i" 21 | $i+=1 22 | 23 | } 24 | 25 | #HighIO 26 | Invoke-Sqlcmd -ServerInstance $server -Database $database -Username $user -Password $password -Query $query -ErrorAction SilentlyContinue -QueryTimeout 0 27 | pop-location 28 | -------------------------------------------------------------------------------- /Lesson09/IntelligentInsights/PowerBiReport.pbix: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/befc9e7e01a12de6ba08d314a28f448eb0e16a65/Lesson09/IntelligentInsights/PowerBiReport.pbix -------------------------------------------------------------------------------- /Lesson09/ReadExtendedEventData.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | -- Get the target data into temporary table 4 | SELECT 5 | se.name AS [XEventSession], 6 | ev.event_name, 7 | ac.action_name, 8 | st.target_name, 9 | se.session_source, 10 | st.target_data, 11 | CAST(st.target_data AS XML) AS [target_data_XML] 12 | into #XEventData 13 | FROM 14 | sys.dm_xe_database_session_event_actions AS ac 15 | 16 | INNER JOIN sys.dm_xe_database_session_events AS ev ON ev.event_name = ac.event_name 17 | AND CAST(ev.event_session_address AS BINARY(8)) = CAST(ac.event_session_address AS BINARY(8)) 18 | 19 | INNER JOIN sys.dm_xe_database_session_object_columns AS oc 20 | ON CAST(oc.event_session_address AS BINARY(8)) = CAST(ac.event_session_address AS BINARY(8)) 21 | 22 | INNER JOIN sys.dm_xe_database_session_targets AS st 23 | ON CAST(st.event_session_address AS BINARY(8)) = CAST(ac.event_session_address AS BINARY(8)) 24 | 25 | INNER JOIN sys.dm_xe_database_sessions AS se 26 | ON CAST(ac.event_session_address AS BINARY(8)) = CAST(se.address AS BINARY(8)) 27 | WHERE 28 | oc.column_name = 'occurrence_number' 29 | AND 30 | se.name = 'LongRunningQueries' 31 | AND 32 | ac.action_name = 'sql_text' 33 | ORDER BY 34 | se.name, 35 | ev.event_name, 36 | ac.action_name, 37 | st.target_name, 38 | se.session_source 39 | ; 40 | GO 41 | -- Parse the target xml xevent into table 42 | SELECT * FROM 43 | ( 44 | SELECT 45 | xed.event_data.value('(data[@name="statement"]/value)[1]', 'nvarchar(max)') AS sqltext, 46 | xed.event_data.value('(data[@name="cpu_time"]/value)[1]', 'int') AS cpu_time, 47 | xed.event_data.value('(data[@name="duration"]/value)[1]', 'int') AS duration, 48 | xed.event_data.value('(data[@name="logical_reads"]/value)[1]', 'int') AS logical_reads 49 | FROM #XEventData 50 | CROSS APPLY target_data_XML.nodes('//RingBufferTarget/event') AS xed (event_data) 51 | ) As xevent 52 | WHERE duration > = 10000000 53 | GO 54 | DROP TABLE #XEventData -------------------------------------------------------------------------------- /Lesson09/Start-Workload.ps1: -------------------------------------------------------------------------------- 1 | ## Code is reviewed and is in working condition 2 | 3 | param 4 | ( 5 | [Parameter(Mandatory=$true)] 6 | [string]$sqlserver, 7 | [Parameter(Mandatory=$true)] 8 | [string]$database, 9 | [Parameter(Mandatory=$true)] 10 | [string]$sqluser, 11 | [Parameter(Mandatory=$true)] 12 | [string]$sqlpassword, 13 | [Parameter(Mandatory=$false)] 14 | [string]$workloadsql="C:\Code\Lesson09\workload.sql", 15 | [int]$numberofexecutions = 10 16 | 17 | ) 18 | 19 | 20 | $sqlserver = $sqlserver + ".database.windows.net" 21 | 22 | for([int] $i=1;$i -le $numberofexecutions;$i++) 23 | { 24 | Write-Host "Iteration $i`:Executing queries in Workload.sql" -ForegroundColor Green 25 | 26 | Invoke-Sqlcmd -ServerInstance $sqlserver -Database $database -Username $sqluser -Password $sqlpassword -InputFile $workloadsql -QueryTimeout 0 | Out-Null 27 | Write-Host "Sleeping for 5 seconds before next execution.." -ForegroundColor Yellow 28 | Start-Sleep -Seconds 5 29 | 30 | } 31 | 32 | Read-Host "Workload execution completed. Press a key to continue"; 33 | 34 | 35 | -------------------------------------------------------------------------------- /Lesson09/workload.sql: -------------------------------------------------------------------------------- 1 | -- Code is reviewed and is in working condition 2 | 3 | SELECT a.* 4 | into #t1 5 | FROM 6 | sys.objects a, 7 | sys.objects b, 8 | sys.objects c; 9 | SELECT 10 | a.* 11 | FROM 12 | Sales.Customers a, 13 | Sales.Orders b 14 | where customername like '%abel%'; 15 | SELECT 16 | a.* 17 | into #t2 18 | FROM 19 | Sales.Customers a, 20 | Sales.Orders b; 21 | SELECT 22 | c.* FROM 23 | Sales.Customers c join Sales.Orders o ON 24 | c.customerid=o.customerid; 25 | -------------------------------------------------------------------------------- /Lesson10/ActivityMachineLearning.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE [dbo].[MonthlySales]( 2 | [year] [smallint] NULL, 3 | [month] [tinyint] NULL, 4 | [Amount] [money] NULL 5 | ) 6 | Go 7 | EXECUTE sp_execute_external_script 8 | @language =N'R', 9 | @script=N'print("Hello World")'; 10 | GO 11 | DROP PROCEDURE IF EXISTS generate_linear_model; 12 | GO 13 | CREATE PROCEDURE generate_linear_model 14 | AS 15 | BEGIN 16 | EXECUTE sp_execute_external_script @language = N'R', 17 | @script = N' 18 | lrmodel <- rxLinMod(formula = amount ~ (year+month), data = MonthlySales); 19 | trained_model <- data.frame(payload = as.raw(serialize(lrmodel, 20 | connection=NULL))); 21 | ' , 22 | @input_data_1 = N'SELECT 23 | year,month,amount FROM MonthlySales', 24 | @input_data_1_name = 25 | N'MonthlySales', 26 | @output_data_1_name = N'trained_ 27 | model' 28 | WITH RESULT SETS 29 | ( 30 | ( 31 | model VARBINARY(MAX) 32 | ) 33 | ); 34 | END; 35 | GO 36 | 37 | DROP TABLE IF EXISTS dbo.monthly_sales_models 38 | GO 39 | CREATE TABLE dbo.monthly_sales_models 40 | 41 | ( 42 | model_name VARCHAR(30) NOT NULL 43 | DEFAULT ('default model') PRIMARY KEY, 44 | model VARBINARY(MAX) NOT NULL 45 | ); 46 | GO 47 | INSERT INTO dbo.monthly_sales_models 48 | ( 49 | model 50 | ) 51 | EXECUTE generate_linear_model; 52 | GO 53 | 54 | SELECT * FROM monthly_sales_models 55 | 56 | GO 57 | INSERT INTO dbo.MonthlySales 58 | ( 59 | year, 60 | month 61 | ) 62 | VALUES 63 | (2019, 7), 64 | (2019, 8), 65 | (2019, 9), 66 | (2019, 10), 67 | (2019, 11); 68 | GO 69 | 70 | DECLARE @salesmodel VARBINARY(MAX) = ( 71 | SELECT model FROM dbo.monthly_sales_models 72 | WHERE model_name = 'default 73 | model' 74 | ); 75 | EXECUTE sp_execute_external_script @language = N'R', 76 | @script = N' 77 | current_model <- unserialize(as.raw(salesmodel)); 78 | new <- data.frame(NewMonthlySalesData); 79 | predicted.amount <- rxPredict(current_model, new); 80 | OutputDataSet <- cbind(new, ceiling(predicted.amount)); 81 | ', 82 | @input_data_1 = N'SELECT [year],[month] 83 | FROM [dbo].[MonthlySales] where amount is null', 84 | @input_data_1_name = 85 | N'NewMonthlySalesData', 86 | @params = N'@salesmodel 87 | varbinary(max)', 88 | @salesmodel = @salesmodel 89 | WITH RESULT SETS 90 | ( 91 | ( 92 | [year] INT, 93 | [month] INT, 94 | predicted_sales INT 95 | ) 96 | ); -------------------------------------------------------------------------------- /Lesson10/monthlysales.dat: -------------------------------------------------------------------------------- 1 | 1974 5 77911.0000 2 | 1971 4 72189.0000 3 | 2001 9 76323.0000 4 | 2004 10 68530.0000 5 | 2015 11 4105.0000 6 | 1979 6 35760.0000 7 | 2009 11 58404.0000 8 | 1985 7 31098.0000 9 | 1955 2 8239.0000 10 | 1966 3 77628.0000 11 | 1996 8 70226.0000 12 | 2007 10 75451.0000 13 | 2015 12 55800.0000 14 | 1952 1 75529.0000 15 | 1982 6 79252.0000 16 | 1977 5 70163.0000 17 | 2012 11 71177.0000 18 | 1958 2 68966.0000 19 | 1955 1 68221.0000 20 | 1985 6 31485.0000 21 | 1963 3 77754.0000 22 | 1993 8 60573.0000 23 | 1969 4 66698.0000 24 | 1983 6 70093.0000 25 | 2013 11 68543.0000 26 | 1991 7 31311.0000 27 | 1999 9 58583.0000 28 | 1964 3 79223.0000 29 | 1961 2 56812.0000 30 | 1994 8 70616.0000 31 | 2002 9 73835.0000 32 | 1972 4 78777.0000 33 | 1950 1 74991.0000 34 | 1980 6 54572.0000 35 | 2010 11 62674.0000 36 | 1961 3 10270.0000 37 | 1991 8 44436.0000 38 | 2018 12 72802.0000 39 | 1988 7 75352.0000 40 | 1953 1 65907.0000 41 | 1967 3 46112.0000 42 | 1973 4 34072.0000 43 | 2008 10 57766.0000 44 | 1951 1 76318.0000 45 | 2003 9 19273.0000 46 | 2016 12 67207.0000 47 | 1981 6 74696.0000 48 | 2011 11 72511.0000 49 | 1978 5 71204.0000 50 | 1959 2 62301.0000 51 | 1989 7 72155.0000 52 | 1954 1 65405.0000 53 | 1967 4 17245.0000 54 | 2019 12 76289.0000 55 | 1997 9 51439.0000 56 | 1975 5 81442.0000 57 | 2005 10 73299.0000 58 | 1970 4 59767.0000 59 | 1986 7 64454.0000 60 | 2000 9 73425.0000 61 | 1997 8 19049.0000 62 | 1956 2 64263.0000 63 | 1976 5 75684.0000 64 | 2006 10 71995.0000 65 | 1992 8 77110.0000 66 | 1962 3 70716.0000 67 | 1987 7 82390.0000 68 | 2017 12 65065.0000 69 | 1957 2 71748.0000 70 | 2003 10 64606.0000 71 | 2014 11 68821.0000 72 | 1984 6 85730.0000 73 | 1973 5 21143.0000 74 | 1979 5 45741.0000 75 | 2009 10 12714.0000 76 | 1960 2 74614.0000 77 | 1990 7 63402.0000 78 | 2020 12 70440.0000 79 | 1968 4 81938.0000 80 | 1998 9 74211.0000 81 | 1965 3 65053.0000 82 | 1995 8 61548.0000 83 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![GitHub issues](https://img.shields.io/github/issues/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition.svg)](https://github.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/issues) 2 | [![GitHub forks](https://img.shields.io/github/forks/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition.svg)](https://github.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/network) 3 | [![GitHub stars](https://img.shields.io/github/stars/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition.svg)](https://github.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/stargazers) 4 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/TrainingByPackt/Professional-Azure-SQL-Database-Administration-Second-Edition/pulls) 5 | 6 | # Professional Azure SQL Database Administration Second Edition 7 | Equip yourself with the skills required to manage and maintain data on the Cloud. 8 | 9 | 10 | Azure SQL Database is the cloud version of SQL Server. It differs in terms of management, maintenance and administration. It’s important to know how to administer SQL Database so that you can get the most out of the features that it provides. This course addresses different management aspects of an Azure SQL Database such as migration, backup and restore, pricing, security, scalability, monitoring and performance optimization, high availability, and disaster recovery. 11 | 12 | # What You Will Learn 13 | 14 | * Understand Azure SQL Database Configuration and Pricing options 15 | * Provision a new SQL Database or Migrate an existing On-Premise SQL Server database to Azure SQL Database 16 | * Backup and Restore Azure SQL Database 17 | * Secure an Azure SQL Database 18 | * Scale an Azure SQL Database 19 | * Monitor and Tune an Azure SQL Database 20 | * Implement High Availability and Disaster Recovery with Azure SQL Database 21 | * Automate common management task with PowerShell 22 | * Develop a scalable cloud solution with Azure SQL Database 23 | * Manage, Maintain and Secure Managed Instances 24 | 25 | ### Hardware requirements 26 | For an optimal student experience, we recommend the following hardware configuration: 27 | * **Processor**: i5 quad core or higher 28 | * **Memory**: 8 GB RAM 29 | * **Hard disk**: 30 GB or more 30 | * An Internet connection 31 | 32 | 33 | 34 | ### Software requirements 35 | You’ll also need the following software installed in advance: 36 | * Operating System: Windows (8.1 or higher) 37 | * Google Chrome 38 | * An Azure subscription 39 | * SQL Server Management Studio 17.2 or above 40 | * PowerShell 5.1 or above 41 | * Microsoft RML Utilities 42 | * Visual Studio 2013 or above 43 | 44 | Note: Rename the parent folder "Professional-Azure-SQL-Database-Administration-Second-Edition" on your local system to something shorter so as to avoid issue when compiling the BruteForceAttack solution in Lesson 5. 45 | --------------------------------------------------------------------------------