Migrate Windows service to Azure

My third Udemy course https://www.udemy.com/course/migrate-windows-service-to-azure covers the thema of Windows service migration to Azure. Taking this course you learn:

  • Cloud service models
  • Benefits of migration to cloud
  • Alternatives for migration
  • Code changes
  • Preparing infrastructure (Azure Portal, Azure PowerShell, Azure CLI, ARM templates)
  • Deployment (Azure Portal, PowerShell)
  • Configuration (.config transformations, Azure Portal)
  • Logging and monitoring (Azure Application Insights)
  • Other options (Azure Functions, Azure Automation, Azure SQL Database Jobs, Hangfire)

Git for busy TFS users

I have 10+ years of experience with TFS and now I have an project which uses Git as source control system. I decided to wrote some notes which can help another experienced TFS users to start with Git. Key differences:

  • Git is decentralized, while TFS has one central repository on TFS server. As for the Git there is one remote repository and then local repositories on developer machines. Due to this, the sync of commits between the repositories is needed.
  • Git has commits, while in TFS we have changesets.
  • Git branches are lightweight, while TFS branches allocates much more disk space.
  • TFS get latest version = Git fetch + pull
  • TFS check-in = Git commit + push

Next I will show some of the basic commands needed for the daily work. We start with cloning remote reposity using command:

git clone <repository_url>

Check the status and display current active branch:

git status

Create new branch:

git checkout -b <branch_name>

Track new file:

git add <file_name>

Commit to local repository:

git commit -m "My commit message"

Push to remote repository:

git push

Display list of last 5 commits:

git log -5

Display list of branches:

git branch

Merge from <other_brach> to current active branch:

git merge <other_branch>

Download commits from remote repository to local repository:

git fetch origin <branch_name>

Apply commits to local repository:

git pull

In this short post I used only command line commands, but this illustrates basic Git usage which can be also done with help of UI.

Run T-SQL query parallel using PowerShell

T-SQL query can be run parallel using combination of PowerShell Workflows and Invoke-Sqlcmd cmdlet as show in following code:

param
(
    [string] $query = $(throw "Query is required"),
    [string] $database = $(throw "Database name is required"),
    [int] $parallelCount = 10
)

workflow Invoke-SqlcmdParallel
{
    param
    (
        $query,
        $parallelCount,
        $database
    )

    $numbers = [System.Linq.Enumerable]::Range(1, $parallelCount)

    foreach -parallel ($number in $numbers)
    {
        Invoke-Sqlcmd -Database $database -Query $query
    }
}

Invoke-SqlcmdParallel -query $query -parallelCount $parallelCount -database $database

Using this script you can easily simulate concurrency.

If you are interested in PowerShell automation, take my Udemy course Improve your productivity with PowerShell.


Udemy course: Improve your productivity with PowerShell

Deliver software faster with Microservices

My second Udemy course https://www.udemy.com/deliver-software-faster-with-microservices covers the thema of microservices. Taking this course you learn:

  • IT today
  • Influencers
  • Microservices architecture
  • Comparison with monolithic architecture
  • Advantages (agility, technology heterogenity, resilience, scaling, deployment, composability, replaceability)
  • Disadvantages (complexity of distributed systems, multiple DB and transactions, testing with dependencies)
  • Real world example
  • Companies using microservices

Create Azure SQL Database using PowerShell cmdlets

Azure SQL Database can be created using UI in Azure Portal, using PowerShell cmdlets or by using Azure Resource Manager template written in JSON. Following PowerShell script creates Azure SQL Database using PowerShell cmdlets:

Udemy course: Improve your productivity with PowerShell

param
(
    $resourceGroup = $(throw "Resource group is required"),
    $location = $(throw "Location is required"),
    $server = $(throw "Server is required"),
    $database = $(throw "Database is required"),
    $adminLogin = $(throw "Admin login is required"),
    $adminPassword = $(throw "Admin password is required"),
    $ipAddress = $(throw "IP address is required")
)

New-AzureRmResourceGroup -Name $resourceGroup -Location $location

$securePassword = ConvertTo-SecureString -String $adminPassword -AsPlainText -Force
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminLogin, $securePassword

New-AzureRmSqlServer -ResourceGroupName $resourceGroup `
    -ServerName $server `
    -Location $location `
    -SqlAdministratorCredentials $credentials

New-AzureRmSqlServerFirewallRule -ResourceGroupName $resourceGroup `
    -ServerName $server `
    -FirewallRuleName "Default" `
    -StartIpAddress $ipAddress `
    -EndIpAddress $ipAddress

New-AzureRmSqlDatabase -ResourceGroupName $resourceGroup `
    -ServerName $server `
    -DatabaseName $database `
    -RequestedServiceObjectiveName "S0"

$result = Invoke-Sqlcmd -ServerInstance "$server.database.windows.net" `
    -Database $database `
    -Username $adminLogin `
    -Password $adminPassword `
    -Query "SELECT @@VERSION AS Version"

$result.Version

PowerShell script creates new resource group, SQL server, configures firewall and than create empty database. At the end new database is queried by simple T-SQL command.

If you are interested in PowerShell automation, take my Udemy course Improve your productivity with PowerShell.