I wrote the following code:
for (int i = 0; i < 100; i++)
{
string connectionString = Configuration.GetConnectionString(DB_CONNECTION_STRING);
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand($"SELECT TOP {i} * FROM PortalObjects", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
I use 3 different connections:
- Azure DB (West Europe) - free version, 5 DTUs;
- Our staging server DB (low performance VM located in West Europe) - MS SQL Express;
- Local computer DB (East Europe) - MS SQL Developer.
All 3 DBs are identical. The PortalObjects table has about 430 records. Running the code on my local computer shows the following timing for the loop execution:
- Azure: 7031 ms;
- Staging: 7145 ms;
- Local: 67 ms.
When I publish the application to Azure (as App Service) and run the loop there:
- Azure: 1668 ms;
- Staging: 1670 ms;
The app service and DB are hosted in the same Azure portal, sharing the same subscription and resource group. I'd expect a timing I get for Azure DB hosting the app in Azure should be ~ equal to timing of local DB on local computer. But my results tell that there is no difference between Azure DB or really 3rd party DB for Azure app service - I found it completely unexpected. Or do I do something wrong?