Azure Web Sites Native C++ DLL (p/invoke)

Sometimes you need improve performance of your code or using library which written on other language. Today we will talk how to create x64 C++ library and how to invoke method in C# Azure Web Site.

  1. Create C++ dll library in VS
  2. In project settings (Linker -> Advanced) set Target Machine to MachineX64 (/MACHINE:X64)
  3. In project setting (C/C++ -> Advanced) set Calling Convention to __cdecl (/Gd)
  4. For example create header and source files with name ExpressionExecuter
  5. In header file define prototype function:
  6. Source file realize method ValidateExpression:
  7. Configure Azure Web Site using method described here
  8. Now we need to realize invoke method in C# project:
  9. Now you can use C++ code using p/invoke in Azure Web Site project:
  10. Don’t forget set X64 configuration settings on staging or production azure web site (Configure Tab -> General -> Platform) select 64-BIT option.

 

Now you have performance code in your C# Azure Web Site project 😉

Searching Azure Table Storage entities using query like Substring or Left

Using Azure Tables Storage we know that selecting primary key and row key one of the most important things. In my situation I decide to make a complex Row Key. It looks like some GUID + “_” + Other Data.

The next step is searching some data that contains first part of Row Key – GUID. For example to delete entities.

First part is prepare batch deletion. To achieve this I find great solution here.

The second part is make Expression – to filter entities using Substring or Left method. For that we can use CompareTo method.

For example I need remove users by project:

Success. Now we know how to search entities using method like Substring or Left for Azure Table Storage.

How to backup and restore Azure SQL Database using SQL Server Management Studio

Before upload new server version or new database script the best practice is to do backup. How it works with Azure SQL Database read below.

Note: You must have SQL Server Management Studio to do next steps.

1. Connect to your SQL Server using Management Studio

Connect to SQL Server

2. Click right button on your database and select Tasks -> “Export Data-tier Application …” to create bacpac package with backup of your data.

Export Data-tier Application ...

Go through wizard and get bacpac package which contains schema and data of your DB.

3. Another option to get just schema of your DB is click right button on your database and select Tasks -> “Extract Data-tier Application …”

Extract Data-tier Application ...

 

Go through wizard and get dacpac package which contains just schema of your DB.

 

Now if something goes wrong you can restore your Azure SQL Database clicking right button on Database folder under your server and select “Import Data-tier Application …” to restore bacpac backup.

Import Data-tier Application ...

 

Have a nice deployments!

Azure Web Role recycling

On one machine, there was an error that didn’t reproduce on other devices.
Web Role can’t start in debug mode with recycling issue.

capture

First of all I checked EmulatorRuntime.log which located in “C:\Users\<user>\AppData\Local\dftmp\EmulatorRuntimeLogs”.

There was a message:

I spend a lot of time trying to fix this issue. Helpful links from stackoverflow.com:

But no one of this solutions solved my problem.

The problem was: Startup Task in ServiceDefinition.csdef made my role recycle.

Solution: So if you have problem with recycling check your startup tasks.