Category: News
OneNote online web app pictures disappearing
Hi community
Using OneNote web / online app only
Have noticed pictures are disappearing (just blank on Chrome/Edge)
On the ipad they appear as a “white image with a red [X] in the centre”
How do I get images to appear again?
Thanks for the support
Hi communityUsing OneNote web / online app onlyHave noticed pictures are disappearing (just blank on Chrome/Edge)On the ipad they appear as a “white image with a red [X] in the centre”How do I get images to appear again?Thanks for the support Read More
function chaining when one function has multiple outputs
Similar question has been asked before, but I would ask the question in a more specific manner. If the function in the input end has more than one output, there will be the error ‘Not enough input arguments’. Is there a neat way to make chained function out of that situation?
f(g) % only the first output of g is kept as input for f
function [x, y] = g()
x = 1;
y = 2;
end
function out = f(x, y)
out = x+y;
end
Storing the outputs of the first function in two variables could be a solution, but I like to see how chaining could be done in this kind of scenario for the sake of learning.
[x, y] = g();
f(x, y)Similar question has been asked before, but I would ask the question in a more specific manner. If the function in the input end has more than one output, there will be the error ‘Not enough input arguments’. Is there a neat way to make chained function out of that situation?
f(g) % only the first output of g is kept as input for f
function [x, y] = g()
x = 1;
y = 2;
end
function out = f(x, y)
out = x+y;
end
Storing the outputs of the first function in two variables could be a solution, but I like to see how chaining could be done in this kind of scenario for the sake of learning.
[x, y] = g();
f(x, y) Similar question has been asked before, but I would ask the question in a more specific manner. If the function in the input end has more than one output, there will be the error ‘Not enough input arguments’. Is there a neat way to make chained function out of that situation?
f(g) % only the first output of g is kept as input for f
function [x, y] = g()
x = 1;
y = 2;
end
function out = f(x, y)
out = x+y;
end
Storing the outputs of the first function in two variables could be a solution, but I like to see how chaining could be done in this kind of scenario for the sake of learning.
[x, y] = g();
f(x, y) chained_function, function_chaining, function_composition MATLAB Answers — New Questions
MATLAB Web Apps are not supported on this device (Phone)
Good night everybody,
I am currently trying to develop a MATLAB Web App on MATLAB Web Server R2020b. This application works fine on Desktop, however if I try to access it on any phone an error "MATLAB Web Apps are not supported on this device" appears. I have accessed the link (https://es.mathworks.com/help/compiler/webapps/supported-browsers-and-platform-incompatibilities.html#:~:text=Web%20apps%20are%20compatible%20with,Chrome%E2%84%A2%20browser%20on%20Chromebooks.) of the error and there is nothing about incompatibility with phones. Are phones and maybe some other devices unhandled by Web Apps or this is some unrelated error which I can’t manage to find? As an example, if I try to access with Chrome or Firefox on a Pixel 2 the error of the image appears, however if I turn on "View in desktop mode" it works correctly and I can see my app.
Thank you all,
MarcosGood night everybody,
I am currently trying to develop a MATLAB Web App on MATLAB Web Server R2020b. This application works fine on Desktop, however if I try to access it on any phone an error "MATLAB Web Apps are not supported on this device" appears. I have accessed the link (https://es.mathworks.com/help/compiler/webapps/supported-browsers-and-platform-incompatibilities.html#:~:text=Web%20apps%20are%20compatible%20with,Chrome%E2%84%A2%20browser%20on%20Chromebooks.) of the error and there is nothing about incompatibility with phones. Are phones and maybe some other devices unhandled by Web Apps or this is some unrelated error which I can’t manage to find? As an example, if I try to access with Chrome or Firefox on a Pixel 2 the error of the image appears, however if I turn on "View in desktop mode" it works correctly and I can see my app.
Thank you all,
Marcos Good night everybody,
I am currently trying to develop a MATLAB Web App on MATLAB Web Server R2020b. This application works fine on Desktop, however if I try to access it on any phone an error "MATLAB Web Apps are not supported on this device" appears. I have accessed the link (https://es.mathworks.com/help/compiler/webapps/supported-browsers-and-platform-incompatibilities.html#:~:text=Web%20apps%20are%20compatible%20with,Chrome%E2%84%A2%20browser%20on%20Chromebooks.) of the error and there is nothing about incompatibility with phones. Are phones and maybe some other devices unhandled by Web Apps or this is some unrelated error which I can’t manage to find? As an example, if I try to access with Chrome or Firefox on a Pixel 2 the error of the image appears, however if I turn on "View in desktop mode" it works correctly and I can see my app.
Thank you all,
Marcos matlab, web app MATLAB Answers — New Questions
Would like to determine when a UDP packet is physically received
Hello,
Is there anyway to determine when a machine physically receives a UDP packet from the network?
Thanks!Hello,
Is there anyway to determine when a machine physically receives a UDP packet from the network?
Thanks! Hello,
Is there anyway to determine when a machine physically receives a UDP packet from the network?
Thanks! udp MATLAB Answers — New Questions
How to send notification when a live feed Excel cell changes value
I have a live data feed inputting to Excel (365) and would like to get notification via txt or email when specific cells hit target values. Is it possible to do this with a Visual Basic macro?
I have a live data feed inputting to Excel (365) and would like to get notification via txt or email when specific cells hit target values. Is it possible to do this with a Visual Basic macro? Read More
Owners of Microsoft team are not granted access to associated SharePoint site
First, the SharePoint site was originally created as a team site and then later a Microsoft team was added to the site. (Site was created before MS Teams existed.) I have noticed that the Owners group for the team / M365 group does not exist in the SharePoint site’s Owners group, therefore when someone is added as an owner to the team, they are not granted permissions to any of the files, stored in SharePoint.
Is there a way to re-add the M365 group owners as owners of the SharePoint site? When attempting to select groups to add, I can only select the Members for the group.
First, the SharePoint site was originally created as a team site and then later a Microsoft team was added to the site. (Site was created before MS Teams existed.) I have noticed that the Owners group for the team / M365 group does not exist in the SharePoint site’s Owners group, therefore when someone is added as an owner to the team, they are not granted permissions to any of the files, stored in SharePoint. Is there a way to re-add the M365 group owners as owners of the SharePoint site? When attempting to select groups to add, I can only select the Members for the group. Read More
Transitioning From Access To Web Sites
I have a question for the individuals out there that are moving to a web interface from Access
What it the best app/program to use to make the move from using Access to using web pages?
I’ve been tasked with converting the Access app that I have been working with for years to make it a web “site”, which would be converting the entire application – forms, reports, etc. so that it can be used via web browser instead of MS Access.
I am in no means a website developer, but I’m always open to learning new things.
Mind you, one of the databases has in excess of 12K lines of VBA. I want to be able to use some of the same techniques as what I’ve done with VBA and to be able to create a good user experience on the front end plus create some additional enhancements.
Al of my searches have not yielded anything helpful.
Thanks in advance.
Jeff
I have a question for the individuals out there that are moving to a web interface from Access What it the best app/program to use to make the move from using Access to using web pages? I’ve been tasked with converting the Access app that I have been working with for years to make it a web “site”, which would be converting the entire application – forms, reports, etc. so that it can be used via web browser instead of MS Access. I am in no means a website developer, but I’m always open to learning new things. Mind you, one of the databases has in excess of 12K lines of VBA. I want to be able to use some of the same techniques as what I’ve done with VBA and to be able to create a good user experience on the front end plus create some additional enhancements. Al of my searches have not yielded anything helpful. Thanks in advance. Jeff Read More
How to apply orientation constraints between two rigid bodies
I am trying to do an inverse kinematics analysis on a rigid body tree that has 3 rigid bodies, all with revolute joints, operating in a 2D plane. One of the contraints of the system that this is based off is that the first and third body must be parallel. How would I apply a constraint to ensure that this happens? I am attempting to mimic the physical motion of the model below, where the base frame is the hole near the top of the 3D model.I am trying to do an inverse kinematics analysis on a rigid body tree that has 3 rigid bodies, all with revolute joints, operating in a 2D plane. One of the contraints of the system that this is based off is that the first and third body must be parallel. How would I apply a constraint to ensure that this happens? I am attempting to mimic the physical motion of the model below, where the base frame is the hole near the top of the 3D model. I am trying to do an inverse kinematics analysis on a rigid body tree that has 3 rigid bodies, all with revolute joints, operating in a 2D plane. One of the contraints of the system that this is based off is that the first and third body must be parallel. How would I apply a constraint to ensure that this happens? I am attempting to mimic the physical motion of the model below, where the base frame is the hole near the top of the 3D model. robotics, inverse kinematics MATLAB Answers — New Questions
Arduino Fails to Program with “avrdude: ser_open(): can’t set com-state” Error
I have an Arduino Uno device and have attempted to attach it to one of my computer’s COM Ports via a USB cable. I have downloaded the MATLAB Support Package for Arduino Hardware, and ensured that it is correctly accessed by my MATLAB installation via the following commands:
>> restoredefaultpath
>> rehash toolboxcache
Following this, I enter the "arduinosetup" command into my MATLAB Command Window, and follow the instructions described in the following MATLAB Documentation:
https://www.mathworks.com/help/supportpkg/arduinoio/ug/configure-setup-for-arduino-hardware.html
I have ensured that I am selecting both the correct board as well as the correct COM port. However, when I press "Program", I receive the following error message:
Failed to program the arduino board. Click the following link to see the error log. Contact Technical support if you need more help.
Clicking the link in that message provides me a TXT file with a fairly large stack trace. The most important lines, however, seem to be at the end. These read the following:
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:ProgramDataMATLABSupportPackagesR2023aaIDEhardwaretoolsavr/etc/avrdude.conf"
Using Port : COM5
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: ser_open(): can’t set com-state for "\.COM5"
avrdude done. Thank you.
An error occurred while uploading the sketch
Upon receiving this error, I tried a few initial troubleshooting steps:Uninstalling and then reinstalling the MATLAB Support Package for Arduino Hardware.Connecting to a different COM port.Restarting both my system and my Arduino board.
Unfortunately, none of the above steps changed the resulting error message. How do I fix this and ensure that I am able to interact with my Arduino board via MATLAB?I have an Arduino Uno device and have attempted to attach it to one of my computer’s COM Ports via a USB cable. I have downloaded the MATLAB Support Package for Arduino Hardware, and ensured that it is correctly accessed by my MATLAB installation via the following commands:
>> restoredefaultpath
>> rehash toolboxcache
Following this, I enter the "arduinosetup" command into my MATLAB Command Window, and follow the instructions described in the following MATLAB Documentation:
https://www.mathworks.com/help/supportpkg/arduinoio/ug/configure-setup-for-arduino-hardware.html
I have ensured that I am selecting both the correct board as well as the correct COM port. However, when I press "Program", I receive the following error message:
Failed to program the arduino board. Click the following link to see the error log. Contact Technical support if you need more help.
Clicking the link in that message provides me a TXT file with a fairly large stack trace. The most important lines, however, seem to be at the end. These read the following:
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:ProgramDataMATLABSupportPackagesR2023aaIDEhardwaretoolsavr/etc/avrdude.conf"
Using Port : COM5
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: ser_open(): can’t set com-state for "\.COM5"
avrdude done. Thank you.
An error occurred while uploading the sketch
Upon receiving this error, I tried a few initial troubleshooting steps:Uninstalling and then reinstalling the MATLAB Support Package for Arduino Hardware.Connecting to a different COM port.Restarting both my system and my Arduino board.
Unfortunately, none of the above steps changed the resulting error message. How do I fix this and ensure that I am able to interact with my Arduino board via MATLAB? I have an Arduino Uno device and have attempted to attach it to one of my computer’s COM Ports via a USB cable. I have downloaded the MATLAB Support Package for Arduino Hardware, and ensured that it is correctly accessed by my MATLAB installation via the following commands:
>> restoredefaultpath
>> rehash toolboxcache
Following this, I enter the "arduinosetup" command into my MATLAB Command Window, and follow the instructions described in the following MATLAB Documentation:
https://www.mathworks.com/help/supportpkg/arduinoio/ug/configure-setup-for-arduino-hardware.html
I have ensured that I am selecting both the correct board as well as the correct COM port. However, when I press "Program", I receive the following error message:
Failed to program the arduino board. Click the following link to see the error log. Contact Technical support if you need more help.
Clicking the link in that message provides me a TXT file with a fairly large stack trace. The most important lines, however, seem to be at the end. These read the following:
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:ProgramDataMATLABSupportPackagesR2023aaIDEhardwaretoolsavr/etc/avrdude.conf"
Using Port : COM5
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: ser_open(): can’t set com-state for "\.COM5"
avrdude done. Thank you.
An error occurred while uploading the sketch
Upon receiving this error, I tried a few initial troubleshooting steps:Uninstalling and then reinstalling the MATLAB Support Package for Arduino Hardware.Connecting to a different COM port.Restarting both my system and my Arduino board.
Unfortunately, none of the above steps changed the resulting error message. How do I fix this and ensure that I am able to interact with my Arduino board via MATLAB? arduino, program, driver, drivers, avrdude, com, port MATLAB Answers — New Questions
thingspeak server closing connection immediately
mqtt3.thingspeak.com closing the connection immediately when trying to connect using A6 gsm module. Has been working flawlessly up to a week ago.Not able to publish any data to private channel. No encryption used (http).mqtt3.thingspeak.com closing the connection immediately when trying to connect using A6 gsm module. Has been working flawlessly up to a week ago.Not able to publish any data to private channel. No encryption used (http). mqtt3.thingspeak.com closing the connection immediately when trying to connect using A6 gsm module. Has been working flawlessly up to a week ago.Not able to publish any data to private channel. No encryption used (http). mqtt broker, tihngspeak MATLAB Answers — New Questions
Theoretical details regarding symbolic integration in Matlab
Dear all,
I am using symbolic integration in Matlab (in particular the "int"-function). I would like to use it as a reference in my research. Therefore, it would be nice to obtain some details which methods Matlab is actually using. Does anybody know? Is there a source to get more details?
Best,
MichaelDear all,
I am using symbolic integration in Matlab (in particular the "int"-function). I would like to use it as a reference in my research. Therefore, it would be nice to obtain some details which methods Matlab is actually using. Does anybody know? Is there a source to get more details?
Best,
Michael Dear all,
I am using symbolic integration in Matlab (in particular the "int"-function). I would like to use it as a reference in my research. Therefore, it would be nice to obtain some details which methods Matlab is actually using. Does anybody know? Is there a source to get more details?
Best,
Michael integration, symbolic, theory MATLAB Answers — New Questions
Bookings calendar not pushing to outlook calendar
We have booked something on bookings and it does not show on outlook. This is weird, because it is only happening every once in a while for absolutely no reason. Today, we got an email saying the appointment was cancelled. But, in fact, it was still listed in bookings as an active appointment but it was no longer on outlook. Is there a reason for this? This person it is happening to has appointments regularly. This is randomly happening and only to her. Wondering if this is a setting I need to change?
We have booked something on bookings and it does not show on outlook. This is weird, because it is only happening every once in a while for absolutely no reason. Today, we got an email saying the appointment was cancelled. But, in fact, it was still listed in bookings as an active appointment but it was no longer on outlook. Is there a reason for this? This person it is happening to has appointments regularly. This is randomly happening and only to her. Wondering if this is a setting I need to change? Read More
Outlook Plugin – Calendar permissions
We are developing a plugin solution that has to connect with our CRM (endpoints provided via Graph QL), allowing clients to schedule, edit, cancel, invite participants to assignments, and request services through it.
We need assistance with a few items:
1) Potential privacy implications of read and write permissions required by the plugin to access users’ calendars.
2) Exposing calendar to personal and corporate accounts without using AD FEDERATION
We are developing a plugin solution that has to connect with our CRM (endpoints provided via Graph QL), allowing clients to schedule, edit, cancel, invite participants to assignments, and request services through it.We need assistance with a few items:1) Potential privacy implications of read and write permissions required by the plugin to access users’ calendars.2) Exposing calendar to personal and corporate accounts without using AD FEDERATION Read More
Records in Access forms with Allow Deletions = No can be deleted with Ctrl+Minus sign (-)
Tested in Microsoft® Access® for Microsoft 365 MSO (Version 2406 Build 16.0.17726.20206) 64-bit
A form with Allow Deletions = No the keyboard shortcut CTRL+Minus Sign (-) results in record deletion. I think this is a bug, and probably a recent one, but can’t be sure. It’s quite serious and has resulted in data loss plus a lot of confusion working out how this could have happened.
Tested in Microsoft® Access® for Microsoft 365 MSO (Version 2406 Build 16.0.17726.20206) 64-bit A form with Allow Deletions = No the keyboard shortcut CTRL+Minus Sign (-) results in record deletion. I think this is a bug, and probably a recent one, but can’t be sure. It’s quite serious and has resulted in data loss plus a lot of confusion working out how this could have happened. Read More
Shared Calendar Not Loading Events for Corporate User
Hi. I am hoping its possible to get some assistance/guidance. Here is the short of the situation:
Our team is developing an Add On for Microsoft Outlook that connects with our pre-existing custom solution that uses GraphQL endpoints. This solution allows our clients to schedule, edit, cancel, and invite participants to events. Our team has requirements surrounding this issue: we don’t want to be able to read the users’ entire calendar/email as it makes us a potential breach point for them. We only want read/write access to a special calendar for our custom solution events.
We have created a special calendar for our users to use but we are having issues with users seeing events on that calendar, particularly when the users are corporate/enterprise users. I’m trying to figure out where and why this error is occuring.
Does anyone have information on this? Or direct me to where I should ask this question?
Hi. I am hoping its possible to get some assistance/guidance. Here is the short of the situation: Our team is developing an Add On for Microsoft Outlook that connects with our pre-existing custom solution that uses GraphQL endpoints. This solution allows our clients to schedule, edit, cancel, and invite participants to events. Our team has requirements surrounding this issue: we don’t want to be able to read the users’ entire calendar/email as it makes us a potential breach point for them. We only want read/write access to a special calendar for our custom solution events. We have created a special calendar for our users to use but we are having issues with users seeing events on that calendar, particularly when the users are corporate/enterprise users. I’m trying to figure out where and why this error is occuring. Does anyone have information on this? Or direct me to where I should ask this question? Read More
Automate shrink database in Azure SQL
While shrinking a database is typically not advised, there may be instances where it is necessary to meet customer requirements. This article aims to simplify the process and provide guidance on automating the shrink operation if needed.
It is generally inadvisable to shrink data files if routine application workloads will cause them to expand to their original size.
For more details – Database file space management – Azure SQL Database | Microsoft Learn
.DESCRIPTION
##############################################################################################################
# This script is used to shrink the database files for a SQL Server database.
# The script will shrink the data files for the specified database to the target free space.
# The script will shrink the data files in chunks of 128 MB until the target free space is reached and increase the chunk size by 64 MB after 2 successful runs.
# The script will reduce the chunk size by 10% if the shrink operation exceeds the MaxRunTimeMinutes value.
# The script will calculate the target free space by adding 30% buffer to the used space.
# Disclaimer: This script is provided as-is, without any warranty or support. Use it at your own risk.
# Before running this script, make sure to test it in a non-production environment and review the impact of the upgrade on your databases and applications.
<#
.SYNOPSIS
##############################################################################################################
.DESCRIPTION
##############################################################################################################
# This script is used to shrink the database files for a SQL Server database.
# The script will shrink the data files for the specified database to the target free space.
# The script will shrink the data files in chunks of 128 MB until the target free space is reached and increase the chunk size by 64 MB after 2 successful runs.
# The script will reduce the chunk size by 10% if the shrink operation exceeds the MaxRunTimeMinutes value.
# The script will calculate the target free space by adding 30% buffer to the used space.
.PARAMETER ServerName
Parameter description of the server name
.PARAMETER DatabaseName
Parameter description of the database name
.PARAMETER Username
Parameter description of the username
.PARAMETER Password
Parameter description of the password
.PARAMETER TargetFreeMB
Parameter description
.PARAMETER InitialShrinkIncrementMB
Parameter description Initial shrink increment in MB
.PARAMETER ShrinkIncrementInMB
Parameter description subsequent shrink increment in MB
.PARAMETER SuccessfulRunCount
Parameter description the number of successful runs before increasing the shrink increment
.PARAMETER MaxRunTimeMinutes
Parameter description the maximum run time in minutes for the shrink operation
.EXAMPLE
An example of how to use this function
Shrink-SqlDatabase -ServerName “ServerName” -DatabaseName “DatabaseName” -Username “Username” -Password “Password”
An example of how to store the output in text file.
Shrink-SqlDatabase -ServerName ‘localhost’ -DatabaseName ‘WideWorldImporters’ -Username ‘userid’ -Password ‘password’
>> c:tempshrink.log
.NOTES
General notes
#>
function Shrink-SqlDatabase{
param (
[string]$ServerName,
[string]$DatabaseName,
[string]$Username,
[string]$Password,
[int]$TargetFreeMB = 0,
[int]$InitialShrinkIncrementMB = 128,
[int]$ShrinkIncrementInMB = 64,
[int]$SuccessfulRunCount = 2,
[int]$MaxRunTimeMinutes = 15,
[int]$Sleeptaskseconds = 15,
[float]$BufferSpace = 0.2
)
function Open-ConnectionAsync {
param (
[string]$connectionString,
[int]$maxAttempts
)
$attempts = 1
while ($attempts -le $maxAttempts) {
try {
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = “$connectionString;MultipleActiveResultSets=True”
# $connection.ConnectionTimeout = 0
$openTask = $connection.OpenAsync()
Start-Sleep -Seconds 5
if ( $openTask.IsFaulted)
{
$openTask.Wait()
}
Start-Sleep -Milliseconds 30
if ($openTask.IsCompleted) {
if (-not $openTask.IsFaulted -and -not $openTask.IsCanceled) {
Write-Host “$(Get-Date) – Connection established successfully.”
return $connection
}
}
}
catch {
$attempts++
$ConnectionerrorMessage = $openTask.Exception.InnerException.Message
Write-Host “$(Get-Date) – Error establishing connection: $ConnectionerrorMessage Retrying in $backoffTime milliseconds…”
break
}
}
Write-Host “$(Get-Date) – Maximum connection attempts reached. Could not establish connection. $ConnectionerrorMessage”
return $null
}
function Resiliency-Check {
param (
[System.Data.SqlClient.SqlCommand]$command
)
if ($command -eq $null -or $command.Connection -eq $null) {
Write-Host “$(Get-Date) – Command or connection object is null. Exiting…”
write-host “CommandObject: $command Connection Object: $command.Connection”
return $false
}
return $true
}
function Execute-QueryAsync {
param (
[System.Data.SqlClient.SqlConnection]$connection,
[string]$query,
[int]$queryNumber,
[int]$maxAttempts
)
for ($i = 1; $i -le $maxAttempts; $i++) {
$queryTimer = [System.Diagnostics.Stopwatch]::StartNew()
try {
$command = $connection.CreateCommand()
$command.CommandText = $query
Write-Host “$(Get-Date) – Attempt $i to execute Query $queryNumber…”
##Command timeout is set to 0 to avoid timeout issues
$command.CommandTimeout = 0
$openTask = $command.ExecuteNonQueryAsync()
Start-Sleep -Seconds 5
if ( $openTask.IsFaulted)
{
$openTask.Wait()
}
while (-not $openTask.IsCompleted) {
Start-Sleep -Seconds $Sleeptaskseconds #frequency to check the task status
}
##Validate command and connection object are still valid
if (-not (Resiliency-Check -command $command)) {
write-host “ResiliencyCheck” $command
return
}
if (-not $openTask.IsFaulted -and -not $openTask.IsCanceled) {
$queryTimer.Stop()
Write-Host “$(Get-Date) – Query $queryNumber, attempt $($i) executed successfully. Execution time: $($queryTimer.Elapsed.ToString())”
return
}
else {
$openTask.Wait() # To throw the exception explicitly
}
}
catch {
$queryTimer.Stop()
$errorMessage = $openTask.Exception.InnerException.Message
Write-Host “$(Get-Date) – Error executing query $queryNumber, attempt $($i): $errorMessage. Execution time: $($queryTimer.Elapsed.ToString())”
break
}
}
}
$exceptionOccurred = $false
try {
$Connection = Open-ConnectionAsync -connectionString “Server = $ServerName; Database = $DatabaseName; User ID = $Username; Password = $Password;” -maxAttempts 1
if ($Connection -eq $null) {
Write-Host “Failed to establish a connection. Exiting…”
return
}
$QueryFiles = “SELECT name, size/128 AS AllocatedMB, FILEPROPERTY(name, ‘SpaceUsed’)/128.0 AS UsedMB FROM sys.database_files WHERE type_desc = ‘ROWS’;”
$CommandFiles = $Connection.CreateCommand()
$CommandFiles.CommandText = $QueryFiles
$Files = $CommandFiles.ExecuteReader()
while ($Files.Read() -and -not $exceptionOccurred) {
$DBFileName = $Files[“name”]
$AllocatedMB = $Files[“AllocatedMB”]
$UsedMB = $Files[“UsedMB”]
$TargetFreeMB = ($UsedMB + ($UsedMB * $BufferSpace))
Write-Output “AllocatedMB: $AllocatedMB”
Write-Output “UsedMB: $UsedMB”
Write-Output “TargetFreeMB: $TargetFreeMB”
if ($AllocatedMB -gt $TargetFreeMB) {
$Files.Close()
$successfulRuns = 0
while ($AllocatedMB -gt $TargetFreeMB -and -not $exceptionOccurred) {
$SizeReduced = 0
$NewTargetSizeMB = [math]::Max($AllocatedMB – $InitialShrinkIncrementMB, $TargetFreeMB)
# Calculate the percentage of free space left
$PercentFreeSpaceLeft = ($AllocatedMB – $TargetFreeMB) / $AllocatedMB * 100
Write-Output (“Percent Free Space Left: {0:N2}%” -f $PercentFreeSpaceLeft)
try {
$shrinkStartTime = Get-Date
Write-Output “ShrinkStartTime: $shrinkStartTime”
# Construct the DBCC SHRINKFILE command with the new target size
$QueryShrink = “DBCC SHRINKFILE (‘$DBFileName’, $NewTargetSizeMB) WITH NO_INFOMSGS;”
# $QueryShrink = “EXEC dbo.SampleLongRunningProcedure”
Execute-QueryAsync -connection $Connection -query $QueryShrink -queryNumber 1 -maxAttempts 1
$elapsedTime = (Get-Date) – $shrinkStartTime
$elapsedMinutes = $elapsedTime.TotalMinutes
Write-Output “Elapsed Time in Minutes: $elapsedMinutes”
# Calculate the percentage left to reach the target free space after each run
# $PercentageLeft = ($AllocatedMB – $TargetFreeMB) / $AllocatedMB * 100
# Write-Host “Percentage left to reach target free space: $PercentageLeft%”
if ($elapsedMinutes -gt $MaxRunTimeMinutes) {
Write-Output “Max duration exceeded. Reducing InitialShrinkIncrementMB by 10%.”
$InitialShrinkIncrementMB = [math]::Max(1, [math]::Round($InitialShrinkIncrementMB * 0.9))
$SizeReduced++
Write-Output “Reducing InitialShrinkIncrementMB by 10%: $InitialShrinkIncrementMB”
}
}
catch {
$exceptionOccurred = $true
Write-Output “Error during shrink: $_”
break # Exit the while loop on exception
}
$QuerySize = “SELECT size/128 FROM sys.database_files WHERE name = ‘$DBFileName’;”
$CommandSize = $Connection.CreateCommand()
$CommandSize.CommandText = $QuerySize
$AllocatedMB = $CommandSize.ExecuteScalar()
$QueryUsed = “SELECT FILEPROPERTY(‘$DBFileName’, ‘SpaceUsed’)/128.0;”
$CommandUsed = $Connection.CreateCommand()
$CommandUsed.CommandText = $QueryUsed
$UsedMB = $CommandUsed.ExecuteScalar()
Write-Output “NewTargetSizeMB: $NewTargetSizeMB”
$successfulRuns++
Write-Output “Successful Run #$successfulRuns”
$shrinkEndTime = Get-Date
Write-Output “shrinkEndTime: $shrinkEndTime”
$shrinkTotalTime = $shrinkEndTime – $shrinkStartTime
Write-Output “shrinkTotalTime: $shrinkTotalTime”
if ($successfulRuns -eq $SuccessfulRunCount -and $SizeReduced -eq 0) {
$InitialShrinkIncrementMB = [math]::Round($InitialShrinkIncrementMB + $ShrinkIncrementInMB)
Write-Output “Increasing InitialShrinkIncrementMB by $ShrinkIncrementInMB : $InitialShrinkIncrementMB”
$successfulRuns = 0 # Reset the successful runs counter
}
if ($AllocatedMB -le $TargetFreeMB) {
break # Exit the while loop if the target size is reached
}
}
$Files = $CommandFiles.ExecuteReader()
}
}
}
catch {
# Handle the exception at the higher level
$exceptionOccurred = $true
Write-Host “Exception occurred: $_”
}
finally {
# Close the connection
if ($Connection -ne $null) {
$Connection.Close()
}
}
}
Microsoft Tech Community – Latest Blogs –Read More
Getting Started with Azure WAF REST API for Azure Front Door: A Step-by-Step Guide
REST API plays a pivotal role in the management of resources on Azure, offering a standardized and methodical approach for handling operations such as create, read, update, and delete (CRUD). The use of HTTP methods, such as GET, POST, PUT, and DELETE, in REST API aligns with CRUD operations, making it intuitive for administrators to manipulate resources on Azure. Additionally, REST API supports a range of data formats, including JSON and XML, providing versatility in how data is consumed and transmitted. This is particularly valuable for automating workflows and enabling continuous deployment and integration practices. Focusing on Azure WAF, we’ll examine its REST API integration for configuring rules, monitoring policies, and real-time threat response, vital for maintaining security in fast-paced cloud deployments. This seamless integration not only enhances security but also ensures that the management of security protocols keeps pace with the rapid deployment cycles inherent in modern cloud environments.
Getting Started
In the following examples, we’ll be using Postman to send our REST API requests to Azure Resource Manager to create, update, and delete the Azure WAF policy. There are other methods and tools to send REST APIs outside of Postman, such as PowerShell, Az CLI, Swagger, and more. The basics will be the same regardless of the tool or method used, just our interface will be different. To follow along, check out the prerequisites below to get started.
Prerequisites:
Link to download Postman: Postman API Platform | Sign Up for Free
Link to blog that covers how to prepare your identities and Postman tool to send REST API commands: Azure REST APIs with Postman (2021) | Jon Gallant
If you’re following along and have followed the prerequisites, you should now have your Postman Collection configured to something similar as below. Our first screenshot shows the Authorization tab in the Postman Collection. We’re going to use the Auth Type of Bearer Token and use the variable from our variables tab.
Next, we have our pre-request script that you can grab from the linked blog above. This script is needed to send the requests continuously to Azure Resource Manager.
Lastly, we have our variables defined to use in our Postman Collection.
With our Postman profiles configured, we can begin managing Azure resources outside of the Azure Portal in a quick and seamless manner. When sending a REST API request, there are mandatory fields that need to be present, depending on the type of request sent. To create a new WAF policy or to update an existing one, we’ll need to use a PUT command, which requires 4 URI parameters and a Request Body.
URI Parameters:
Example of the request URI: PUT https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroup}}/providers/Microsoft.Network/FrontDoorWebApplicationFirewallPolicies/{{fdWafPolicy}}?api-version=2024-02-01
Request Body:
When sending a GET request, we no longer require the request body, only the URI parameters to pull the information for the resource we want.
Creating a policy
Let’s start with creating an out of the box WAF policy with only the minimum requirements. We’ll then add on as we go, setting our Policy configurations like request body inspection, creating Custom rules, and managing actions and exclusions on our Managed rulesets. The API for WAF Policies consists of 3 main blocks; properties.policySettings, properties.customRules, and properties.managedRules. Starting off, we’ll leave out the customRule block and visit that later in the document. For these examples, we’ll use Azure WAF on Azure Front Door.
Deploying an out of the box Azure WAF Policy requires providing a name, the SKU, a location, and to define which managed rulesets you want to use. With REST API, the name will be sent along with the URI parameters and not part of the request body. In Postman, ensure that the method is set to PUT, and under the ‘Body’ tab, select raw and then JSON from the drop-down selection. The following JSON will create a new Azure WAF Policy for Azure Front Door and will use the latest DRS 2.1 Managed Ruleset and Bot Manager Ruleset 1.1. We’ll set the SKU to Premium_AzureFrontDoor, since not specifying a SKU will default to Classic_AzureFrontDoor. Since the WAF policy will be associated with an Azure Front Door profile, the location of the policy will be set to Global. We’ve also set the WAF into ‘Prevention’ mode and enabled the policy under the property.policySettings.
{
“location”: “Global”,
“properties”: {
“policySettings”: {
“enabledState”: “Enabled”,
“mode”: “Prevention”
},
“managedRules”: {
“managedRuleSets”: [
{
“ruleSetType”: “Microsoft_DefaultRuleSet”,
“ruleSetVersion”: “2.1”,
“ruleSetAction”: “Block”
},
{
“ruleSetType”: “Microsoft_BotManagerRuleSet”,
“ruleSetVersion”: “1.1”,
“ruleSetAction”: null
}
]
}
},
“sku”: {
“name”: “Premium_AzureFrontDoor”
}
}
After sending the PUT command to create the policy, we’ll use a GET to pull the resource and check out what’s been created. It’s important to check the provisioning state and ensure that it is in a Succeeded state before sending another PUT. Sending another PUT while the policy is updating will place the WAF policy into a failed state. As a best practice, always check the provisioning state of all your resources before committing any changes.
Using the example below, we can see the name that was passed through the URI parameters, our location, the state and mode of the policy, and which managed rulesets we’ve enabled. You’ll also notice that there are attributes of the policy that we never defined but are now present. This is because there are default values that are applied to Azure WAF policies when created if not explicitly defined, one of them being the enforcement of request body inspection.
With this simple example, we can already see how REST API is a flexible and quick way to create and manage resources in Azure. This method allows us to see exactly how a resource is configured in JSON, without having to navigate multiple blades in the Azure Portal.
Policy Settings
With our out of the box policy set, let’s begin configuring additional policy settings to customize our Azure WAF policy to our needs.
What we’ll cover in this section will be:
In this block of JSON under properties.policySettings, we’re making changes to default values that were created for the policy around redirects, custom blocks, and JavaScript challenges to better fit our needs. If you ran a GET against the Policy, you’ll see that most of these values returned with null. In our example, we’ll set our redirect to land on the Azure WAF Overview Learn documentation, our JavaScript challenge expiration to 5 minutes, the custom block code to 403, and lastly use HTML in the custom block response body to show the Azure Front Door tracking reference ID for easier troubleshooting.
You’ll notice in the above table that the customBlockResponseBody must be specified in base64 encoding. We’ll have to take our HTML response below and encode this with base64. You’ll be able to do this conversion with any search engine tool and paste the results in the JSON body.
<html><head><title>Azure WAF Block</title></head><body bgcolor=”#FFB299″><p><h1><strong>WAF Custom Response Page</strong></h1></p> <p> Please contact us with {{azure-ref}} <br></P></body></html>
To safeguard sensitive data and personally identifiable information (PII), we’ve enabled log scrubbing rules to scrub requestor IPs, password values that are sent in JSON body, and client IDs that come in as a request header.
Our block of JSON for these changes should look like below.
“policySettings”: {
“enabledState”: “Enabled”,
“mode”: “Prevention”,
“redirectUrl”: “https://learn.microsoft.com/en-us/azure/web-application-firewall/overview“,
“customBlockResponseStatusCode”: 403,
“customBlockResponseBody”: “PGh0bWw+PGhlYWQ+PHRpdGxlPkF6dXJlIFdBRiBCbG9jazwvdGl0bGU+PC9oZWFkPjxib2R5IGJnY29sb3I9IiNGRkIyOTkiPjxwPjxoMT48c3Ryb25nPldBRiBDdXN0b20gUmVzcG9uc2UgUGFnZTwvc3Ryb25nPjwvaDE+PC9wPiA8cD4gUGxlYXNlIGNvbnRhY3QgdXMgd2l0aCB7e2F6dXJlLXJlZn19IDxicj48L1A+PC9ib2R5PjwvaHRtbD4=”,
“requestBodyCheck”: “Enabled”,
“javascriptChallengeExpirationInMinutes”: 5,
“logScrubbing”: {
“state”: “Enabled”,
“scrubbingRules”: [
{
“matchVariable”: “RequestIPAddress”,
“selectorMatchOperator”: “EqualsAny”,
“selector”: null,
“state”: “Enabled”
},
{
“matchVariable”: “RequestBodyJsonArgNames”,
“selectorMatchOperator”: “Equals”,
“selector”: “password”,
“state”: “Enabled”
},
{
“matchVariable”: “RequestHeaderNames”,
“selectorMatchOperator”: “Equals”,
“selector”: “client_id”,
“state”: “Enabled”
}
]
}
},
Once the PUT is sent through and the WAF is in a ‘Succeeded’ state, you can run a GET like we did in the last section to check how the policy is configured.
Custom Rules
Custom rules allow you to create your own rules that are evaluated for each request that passes through the WAF. These rules hold a higher priority than the rest of the rules in the managed rule sets. The custom rules contain a rule name, rule priority, and an array of matching conditions. If these conditions are met, an action is taken (to allow, block, javascript challenge or log). Custom rules have two different types of rules, MatchRule and RateLimitRule. Most custom rules will fall under the MatchRule type, including GeoMatch, while RateLimitRule will apply for any rule that has rate limiting configured for a specified condition.
Our first custom rule example shows how to create a Geomatch custom rule to block global regions that we don’t want to access the backend application. To learn more about Geomatch custom rules and suggested patterns, you can review this blog here. Here we are blocking North Korea (KP) and Russia (RU) and assigning a priority of 10 to the rule. The operator for this kind of custom rule will need to be ‘GeoMatch’ rather than a more common one like ‘contains’.
Geo Block Example:
“customRules”: {
“rules”: [
{
“name”: “GeoBlockRule”,
“enabledState”: “Enabled”,
“priority”: 10,
“ruleType”: “MatchRule”,
“matchConditions”: [
{
“matchVariable”: “SocketAddr”,
“selector”: null,
“operator”: “GeoMatch”,
“negateCondition”: false,
“matchValue”: [
“KP”,
“RU”
],
“transforms”: []
}
],
“action”: “Block”,
“groupBy”: []
},
Next, we’ll work on creating a rate limit custom rule that limits the amount of traffic coming to the request URIs of ‘search’ and ‘login’. You’ll notice there are extra parameters that need to be defined within the rule that aren’t relevant to MatchRule types. The parameters ‘rateLimitDurationInMinutes’ allow you to configure either ‘1’ or ‘5’ as the integer and ‘rateLimitThreshold’ also requires an integer to be specified. Additionally, you’ll need to define the ‘groupBy’ parameter to determine how the requests will be grouped for the rule. To learn about rate limiting, read more about it here.
Rate Limit Example:
{
“name”: “RateLimitRequests”,
“enabledState”: “Enabled”,
“priority”: 20,
“ruleType”: “RateLimitRule”,
“rateLimitDurationInMinutes”: 5,
“rateLimitThreshold”: 100,
“matchConditions”: [
{
“matchVariable”: “RequestUri”,
“selector”: null,
“operator”: “Contains”,
“negateCondition”: false,
“matchValue”: [
“/search”,
“/login”
],
“transforms”: []
}
],
“action”: “Block”,
“groupBy”: [
{
“variableName”: “SocketAddr”
}
]
},
Finally, let’s investigate how to create a custom rule that requires multiple conditions to be met for the action to take effect. When constructing a rule that requires multiple conditions, all our parameters will be the same, with only the key difference in the ‘matchConditions’ array. The array allows us to specify multiple match variables and match values within their own block, since an array is a collection of items of the same data type. You’ll find the first block of match conditions in orange and the second block of match conditions in green. Both blocks must be fulfilled for the custom rule to take effect and for the action to execute.
Multi-Condition Example:
{
“name”: “UserAgentAndUriBlock”,
“enabledState”: “Enabled”,
“priority”: 30,
“ruleType”: “MatchRule”,
“matchConditions”: [
{
“matchVariable”: “RequestHeader”,
“selector”: “User-Agent”,
“operator”: “Contains”,
“negateCondition”: false,
“matchValue”: [
“rv:125.0”
],
“transforms”: []
},
{
“matchVariable”: “RequestUri”,
“selector”: null,
“operator”: “Contains”,
“negateCondition”: false,
“matchValue”: [
“login”
],
“transforms”: []
}
],
“action”: “Block”,
“groupBy”: []
}
]
},
This block of custom rules is fairly large, so we aren’t able to capture how this will look in our example below, but we can see how the block will fit within the JSON to apply to the policy.
With every step, once the PUT has been executed, feel free to run a GET to ensure that the new configurations have gone through and that the provisioning state is ‘Succeeded’.
Managed Rules Actions and Exclusions
We’ve already configured what managed rulesets we’ll use with the policy, so now we’ll determine rules that may need to have their actions changed or if rules need to be completely disabled to meet our needs. Below, we’ve carved out some rules under the ‘SQLI’ rule group to completely disable. We’ve also changed the ‘action’ of a rule within the ‘PROTOCOL-ENFORCEMENT’ rule group to Log, rather than disabling completely. These actions can be made against rules to assist in fine tuning the WAF, reducing the amount of false positives seen within the WAF logs.
“managedRuleSets”: [
{
“ruleSetType”: “Microsoft_DefaultRuleSet”,
“ruleSetVersion”: “2.1”,
“ruleSetAction”: “Block”,
“ruleGroupOverrides”: [
{
“ruleGroupName”: “PROTOCOL-ENFORCEMENT”,
“rules”: [
{
“ruleId”: “920160”,
“enabledState”: “Enabled”,
“action”: “Log”,
“exclusions”: []
}
],
“exclusions”: []
},
{
“ruleGroupName”: “SQLI”,
“rules”: [
{
“ruleId”: “942160”,
“enabledState”: “Disabled”,
“action”: “AnomalyScoring”,
“exclusions”: []
},
{
“ruleId”: “942100”,
“enabledState”: “Disabled”,
“action”: “AnomalyScoring”,
“exclusions”: []
}
],
“exclusions”: []
}
],
“exclusions”: []
},
Exclusions can be key to tuning a WAF policy to isolate specific keys or key values that could be generating many false positives for the backend application. These exclusions can be applied to the entire WAF policy, to a rule group, or directly on a rule ID. Applying exclusions at different levels allows for more granular control to meet the application needs. Below we have examples of exclusions created for RequestCookieValues globally, and for RequestArgValues that will be applied strictly to two XSS rule ids.
{
“ruleGroupName”: “XSS”,
“rules”: [
{
“ruleId”: “941320”,
“enabledState”: “Enabled”,
“action”: “AnomalyScoring”,
“exclusions”: [
{
“matchVariable”: “RequestBodyPostArgNames”,
“selectorMatchOperator”: “StartsWith”,
“selector”: “comment”
}
]
},
{
“ruleId”: “941330”,
“enabledState”: “Enabled”,
“action”: “AnomalyScoring”,
“exclusions”: [
{
“matchVariable”: “RequestBodyPostArgNames”,
“selectorMatchOperator”: “StartsWith”,
“selector”: “comment”
}
]
}
],
“exclusions”: []
}
],
“exclusions”: [
{
“matchVariable”: “RequestCookieNames”,
“selectorMatchOperator”: “Equals”,
“selector”: “continueCode”
}
]
Our example below shows how to place these blocks into the overall JSON file, all falling within the ‘managedRules’ block. Be aware that the global ‘exclusions’ block is comma separated from the ‘ruleGroupOverrides’ block.
With our final configurations made against the WAF policy, we can send the last PUT to Azure Resource Manager to use the policy to secure our backend web applications. Once complete, run a GET command to see how the WAF policy is configured and to save this configuration for later use. If you’ve followed along with the examples, your JSON file should be around 200 lines.
Deleting a Policy
Deleting an Azure WAF policy with REST API is simple, as you only need to send the request with DELETE selected as the HTTP method. Once the request is sent, the policy will be removed from the environment.
Conclusion
In this guide, we’ve learned how to use the Azure REST API to create and configure an Azure Web Application Firewall policy. We have seen how to use Postman to send HTTP requests to the Azure Resource Manager endpoint and how to authenticate with Azure Entra ID. We have also explored how to customize the WAF policy by enabling or disabling rule sets, overriding rules, and adding exclusions. By using the Azure REST API, we can automate and streamline the process of securing our web applications with the WAF policy. To learn more about Azure REST API and Azure WAF, check out the referenced documentation below.
References
Azure REST API reference documentation | Microsoft Learn
Policies – REST API (Azure Front Door Service) | Microsoft Learn
Azure REST APIs with Postman (2021) | Jon Gallant
Postman API Platform | Sign Up for Free
What is Azure Web Application Firewall on Azure Front Door? | Microsoft Learn
Azure Web Application Firewall DRS rule groups and rules | Microsoft Learn
Web application firewall custom rule for Azure Front Door | Microsoft Learn
Web application firewall exclusion lists in Azure Front Door | Microsoft Learn
Policy settings for Web Application Firewall in Azure Front Door | Microsoft Learn
Azure Web Application Firewall on Azure Front Door Sensitive Data Protection | Microsoft Learn
Web application firewall rate limiting for Azure Front Door | Microsoft Learn
Azure Web Application Firewall JavaScript challenge (preview) overview | Microsoft Learn
Microsoft Tech Community – Latest Blogs –Read More
Join Microsoft Ignite as a Featured Partner!
This November 18-22, 2024, Microsoft Ignite will bring together the best of customer, partner, and executive decision-maker experiences in Chicago and online. Answering the call from customers and partners alike for more joint learning, networking, and meeting opportunities, Microsoft Ignite is now more than a technology conference—it’s a celebration of the AI innovators transforming their organizations and industries with Microsoft. Become an Ignite Featured Partner! Packages are available to reach any audience at a range of price points, including entry-level.
Find out more at Microsoft Event Sponsorships
Microsoft Tech Community – Latest Blogs –Read More
Copilot for Service – Member Services for Payer Contact Center – HLS Snacks!
Unlocking Efficiency in Member Service Contact Centers with Copilot for Service
This discussion shows how Copilot for Service can be used to enhance member service and customer service use cases by seamlessly integrating with third-party CRM systems, such as Salesforce and ServiceNow
To see all HLS Copilot Snacks video click here.
Microsoft Tech Community – Latest Blogs –Read More
Why do I get different results on different machines when using “fmincon” from the Optimization Toolbox?
When I try to optimize my objective function with "fmincon", the optimization exits with a flag 0. However on a different machine, it exits with a flag 5. Why do these results differ?When I try to optimize my objective function with "fmincon", the optimization exits with a flag 0. However on a different machine, it exits with a flag 5. Why do these results differ? When I try to optimize my objective function with "fmincon", the optimization exits with a flag 0. However on a different machine, it exits with a flag 5. Why do these results differ? fmincon, condition, firstorderopt, optimization, numericalreproducibility MATLAB Answers — New Questions