THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

Davide Mauri

A place for my thoughts and experiences the Microsoft Data Platform

Azure Functions, Dapper and SQL Server JSON to store form data

A common problem

Recently we had to setup a couple of contact form pages to allow users to register to the App 2.0 Beta program (now RTM) or to tell us which of the products we launched at CES 2017 they are interested into.

Such kind of request are quite frequent and usually, from a developer perspective, they are the worst thing someone can ask. They are boring to architect, boring to write, boring to test. Still, business and marketing needs and love them.

So how to satisfy this requirement in the fastest and easiest way, but still delivering high-quality and easy to maintain code, while also keeping an eye on integrating the data with the existing environment?

Evaluating Azure DocumentDB

Given that we are on Azure, one option was Azure DocumentDB. No need to define a schema upfront and it is usable just using REST so the UX developer could do anything on its own, just using JQuery. Azure DocumentDB can also be queried using a SQL language, so extracting data from it wouldn’t have been a problem.

But at the end, I decided to go another way. All our data, after swimming in a Data Lake are saved in a Azure SQL database where we heavily rely on its column-store features. So having an additional database to integrate was something that would have made the solution a bit more more complex than the simplest possible one. The famous quote

everything should be made as simple as possible, but no simpler

is what drives all my architectural decisions, so I wasn’t really happy about going with Azure DocumentDB.

With the additional fact that there are no really good tooling around Azure DocumentDB yet, I started to look for alternatives. The obvious alternative, aside from saving data into a blob, which was not on option since that would have been too simple, because it doesn’t offer any querying capability, was to use Azure SQL.

Moving to Azure SQL?

With Azure SQL you have great tooling (SQL Server Management Studio and now also the online query editor), we already have all knowledge in house, but surely the fact that it doesn’t allow to use just REST to read and write data was, again, something that wasn’t making me really happy.

Beside that, Azure SQL seemed to be the perfect option. JSON is now natively supported, so there is no problem to store data without a strictly enforced schema.

Since we’re already using SQL Azure, we wound’t even have to spend any additional cent for it. The only problem to solve was that you can’t use Azure SQL directly via JQuery.

Serverless is the key

The missing link — the REST interface — can easily be created using Azure Functions and a microORM like Dapper. Thanks to the serverless nature of Azure Functions all it’s need are the few lines of code to get the HTTP Request Body that contains the contact form “jsonifyied” data and store into the SQL Azure database.

The created Azure Function gets called each time an HTTP Request is done, using an HTTP Trigger. Here the function.json file that defines the function bindings:

"bindings": [
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in"
"name": "res",
"type": "http",
"direction": "out"
"disabled": false

and the function full code is here:

Such additional layer is also a welcome addition since it allows to inject some additional validation checks and business if needed.

I’ve used a Stored Procedure here for better decoupling, and it does just a simple insert, with some additional checks.

It also turns some JSON data into columns, to make querying even easier.

Dapper helps to make interacting with SQL Azure a breeze (two, yes two, lines of code to open the connection and write to SQL azure), so all simplicity requirements are finally met. No more impedance mismatch. No more.

Given the existing external factors (resources, knowledge, integration) the simplest solution but not simpler has been achieved.

Without any existing factors I would probably have chosen Azure DocumentDB. But as an afterthought, I still have the gut feeling that SQL Azure would have been better in the long term (for example I can connect Marketing Manager’s Excel directly to the SQL Azure, something that I cannot do yet with DocumentDB)…so maybe SQL Azure would be my choice onve again. After all software is made to serve people, and this should drive at least 50% (if not more) of the architectural choices, IMHO.

In conclusion

Since I joined Sensoria I’ve moved to work on the cloud 100% of my time. And the more I work on the cloud, the more it is clear to me that serverless and simplicity (which means, implementation-wise: microservices) is the way to go. Efficiency is increased so much in this way that it’s really worth the effort, and embracing PaaS clearly becomes an obvious choice.

Published Sunday, February 5, 2017 7:01 PM by Davide Mauri

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS



Reza said:

Hi Davide,

Thanks for the article. I wonder if I can use a SQL Server provisioned in Azure and connect to it from the App Functions?

I already have my function app in the same VNET as my SQL Server VM in Azure. However the Integration to SQL Table as the App Function Integration points out, does not work; does it need special coding or can be done similarly you stated above?

Any thoughts?

Thanks in advance,


February 24, 2017 10:56 AM

Pranay said:

Hi Davide,

Thanks for the work above. Really helpful, and many things to learn from one complete example.

Quick note: I had to add a project.json file on azure functions to reference dapper and sqlclient. Here is what I added.


 "frameworks": {


     "dependencies": {

       "Dapper": "1.50.2",







April 5, 2017 3:12 AM

abx said:


May 31, 2018 11:06 PM

dongdong8 said:



June 29, 2018 3:32 AM

dongdong8 said:



July 23, 2018 11:44 PM

Yeezy Supply said: Jordan 11 Win Like 82 Nike Outlet Store Nike Outlet Store Yeezy Yeezy Moncler UK Yeezy Boost 350 Yeezy Boost 350 V2 Birkenstock Oakley Outlet Nike Outlet Online"> nike clearance Off White Jordan 1 Nike Air Max Yeezy Boost 350 Air Max 97 jordan 12 bordeaux Yeezys Nike Shoes Nike Outlet Air Max 2017 Moncler Jackets Yeezy Boost 350 V2 Jordan 12 Win Like 82 Jordan 11 Win Like 82 jordan 4 Nike Clearance Moncler UK Yeezy Nike Outlet Store Online Shoping Birkenstock Shoes jordan 12 ovo Nike Air Max 2017

August 14, 2018 7:35 PM

qqq said:

August 16, 2018 12:33 AM

chenjinyan said:


August 22, 2018 11:15 PM

shenyuhang said:


August 23, 2018 10:30 PM

chenlixiang said:



September 18, 2018 10:07 PM

kakakaoo said:

October 8, 2018 2:04 AM

chenjinyan said:


October 9, 2018 6:53 PM

chenqiuying said:


October 10, 2018 6:33 PM

Leave a Comment


About Davide Mauri

Director of Software Development & Cloud Infrastructure @ Sensoria, an innovative smart garments and wearable company. After more than 15 year playing with the Microsoft Data Platform, with a specific focus on High Performance databases, Business Intelligence, Data Science and Data Architectures, he's now applying all his skills to IoT, defining architectures to crunch numbers, create nice user experiences and provide meaningful insights, all leveraging Microsoft Azure cloud. MVP on Data Platform since 2006 he has a very strong background development and love both the ER model and OO principles. He is also a fan of Agile Methodology and Automation, which he tries to apply everywhere he can, to make sure that "people think, machines do".

This Blog


Privacy Statement