Table Value Parameters in an Update

Table Value Parameters are really powerful, but there’s almost no documentation (here’s the best I found, and this helps a bit) on how to use them in an Update. So here we go:

First create a type in the database (not a table). You do this as follows:


( UserId INT,

  BandwidthThisMonth BIGINT,

  MailsHeldThisMonth BIGINT,



Then you code it up as follows:

protected virtual void _UpdateStatus(IDbConnection conn, IEnumerable<UserStatus> userStatus)



    // put the params in a table

    DataTable table = new DataTable();

    table.Columns.Add("UserId", typeof(int));

    table.Columns.Add("BandwidthThisMonth", typeof(long));

    table.Columns.Add("MailsHeldThisMonth", typeof (long));

    table.Columns.Add("MostRecentEmail", typeof (DateTime));

    foreach (UserStatus statOn in userStatus)

        table.Rows.Add(statOn.UserId, statOn.AdditionalBandwidth, statOn.AdditionalMailsHeld, statOn.MostRecentEmail);


    using (IDbCommand cmd = conn.CreateCommand())


        cmd.CommandText = "update [User] set " +

                          "[User].BandwidthThisMonth = [User].BandwidthThisMonth + stats.BandwidthThisMonth, " +

                          "[User].MailsHeldThisMonth = [User].MailsHeldThisMonth + stats.MailsHeldThisMonth, " +

                          "[User].MostRecentEmail = stats.MostRecentEmail " +

                          "from [User] inner join @TableStats as stats on [User].UserId = stats.UserId";



            new SqlParameter()


                ParameterName = "@TableStats",

                SqlDbType = SqlDbType.Structured,

                TypeName = "ParamsUserStats",

                Value = table,







You are creating a DataTable that matches the type you added to the database. You then join this passed in table to the table you are updating, and the rest is pretty straightforward.

Posted in Uncategorized | Comments Off on Table Value Parameters in an Update

Getting Started on Azure

We’re doing some work on a new product on Azure and it’s been a learning process. For any of you that are just getting started, here’s what I’ve found to be the most useful information getting started.

Transient connections

Connections will drop. Regularly. Your application MUST be able to handle dropped connections. Dropped connections are inevitable and intrinsic to the cloud architecture (e.g. ops like replacing a dead node, splitting a Federation member in SQL Database, etc.). The Transient Fault Handling Application Block provides well thought out and tested ways to handle this – use it.

Network latency

A SQL select that normally takes 10 milliseconds to complete can take a minute. Azure is a service-based platform of shared resources, and this means that two types of latencies or interruptions regularly occur. The first is the time taken to make a request and receive a response over the internet. Since those requests and responses can travel through any number of routers before they return to the client, timeouts and disconnections are more frequent than in local, fixed networks. The second is the time it takes for a shared-resource system like Azure to create backup versions of data for durability and to replace and reroute requests to any removed instances. In some cases that means the user waits a minute for the web page to complete. But for other uses, it means perform your communication with other systems in Azure in an async manner.

Two Datacenters

Even if the only user of your app at first will be your proud mom, set it up on two datacenters. There’s a giant difference between a single instance and two instances. Going from 2 to N has some issues, but they’re a lot fewer. Learn from the start how to properly set up a clustered system. We set one in the US and one in Europe so we hit more latency and communication problems between the two systems.

Default Capacity & Billing Settings

When you create anything in Azure, it has default limits set for capacity, billing, etc. Check them. You don’t want a well-designed system to stop responding, not because it can’t handle the load, but the increased number of customers caused you to hit the maximum charge for one of the services. We hit this problem with the Phone Home license server which caused it to be down for ½ hour.

Web App Logging

Using Trace sucks. There’s no way to set the level of logging by component and no log.IsDebugEnabled which is a tremendous performance win. We’re still working through how to best configure log4net and will update this here when we make a final decision. (A big question is do we log to each web app instance local storage, and lose that logging if the web app VM crashes, or do we write out to shared storage.)

Great Links


Storing Passwords & Sensitive Data

This is a problem. The Azure team assumes that no one can get to your Azure management login (and that is unlikely). But they also assume all administrators of the site should have access to all sensitive information, and that is not a good practice. Especially for private keys where the public key is embedded in local programs and therefore cannot be changed.


Cloud Services

Azure Sql Database

Most important thing to watch for on info out there for Sql Azure – most of it is way out of date. And there’s no easy way to determine if the page you found or were referred to is correct.

Storage & Queues


At the Build Conference I attended a session by two of the top Azure system engineers. They had a slide come up labeled “Load Testing” and they said “take it live.” Their point was you can, and should load test before you go live. But it’s only as a live system that you truly test it and find the problems from that testing.

Running on Azure is new, different, and a learning experience. Be ready to resolve issues quickly because you will hit quite a few when you first go live. And by definition, most of them will be in unexpected places.

Posted in Uncategorized | Comments Off on Getting Started on Azure

How often do you provide your contact info to get a white paper?


Software Developers only please!

We had a major “discussion” at lunch today where the marketing people said developers are willing to provide contact information (name & email) to get a white paper. And several of us on the development side said we rarely do this. To help settle the argument, how often will you trade your contact info for a white paper?

Posted in Uncategorized | Comments Off on How often do you provide your contact info to get a white paper?

The Four Greatest Crimes of the First Semi-Final

The results of the first semi-final had four gross miscarriages of justice. Call the police level of crime. Europe, what were you thinking?



This was a beautiful evocative song celebrating what mothers give us. If you have a heart it brought tears to your eyes. It ripped out your heartstrings better than any other entry except Hungary. It deserved top 10 in the final. I hope the mothers of every jury member that did not put this in the top 5 has a “discussion” with their child. A long & painful discussion.


WTF? This was the worst song of the night. This is the one song that made me wish I was at home instead of the arena so I could take a 3 minute bathroom break. And this made it while the others on this list did not. Europe, you clearly showed the judgment skills of a preschooler. And for this you need to go into time-out.


Ok, so Suzy did not come out of a disco ball spaceship. But this was every bit as good a number with an Iberian flair. This is the quintessential Eurovision number and there must be an entry like this in the final. I’m guessing this lost due to the jury vote. If so, then the juries don’t understand what Eurovision is.


How, how, how did Moldova lose when Azerbaijan won? Cristina had the most interesting voice of any act last night. Incredible presence and personality in her presentation. An act that supported the song perfectly. A very strong and interesting song. And she sang it beautifully. Were the votes going elsewhere out of habit? Because Cristina deserved to be in the top 5 of the semi.

Posted in Uncategorized | Comments Off on The Four Greatest Crimes of the First Semi-Final

The First Semi-Final

Last night was the first semi-final and it was incredible. I love Eurovision, but I don’t listen to any of the songs before the shows, I don’t go to the dress rehearsals. So last night was the first time I saw any of them. And wow, what an impact. So here they are in order of how good I thought they were.


Hungary (video)

Absolutely amazing. I think this is the best act of the entire show. It’s a dark story, and dance, about child abuse. And it treats it seriously, no sugar coating, no Disney ending. And it works. It works very very well. I was mesmerized for the entire song. He’s done something close to impossible, made it work very well about such a serious topic.

Ukraine (video)

Ukraine sends incredible singers (and beautiful women) year after year and this year was no exception. Again it was incredible staging. How that dancer makes it through the 3 minutes in the hamster wheel without getting too dizzy is beyond me. And Mariya takes an amazing song and puts every bit of her heart into it. Great song rendered beautifully.

Belgium (video)

This one tears at your heartstrings. He sings about mothers, how they’re warm, nurturing, loving – it had me crying part way in to it. It’s mostly Axel standing up there and singing his heart out and he does an amazing job. How this did not go on to the final is beyond me. The presentation is simple, but powerful in the simplicity and he emotes his love for his mother, for all mothers very clearly.

Sweden (video)

Sanna delivers a knock-out performance. Great song, incredible voice, great staging. The reason I have it down here in 4th place is this fits the formula for the perfect Eurovision song. She nails it, but following the formula perfectly is still following the formula.

Russia (video)

The Tolmachevy Twins make use of the fact their twins without overplaying it. It’s a great Russian pop number (I love Russian & Ukrainian pop). The staging is clever, the song is really good, and the girl’s voices are incredible together. This could well be the one I listen to the most a year from now.

On a related note, a lot of the audience boo-ed when they started and again at the end. That is so inappropriate. First off, I’m pretty sure they are not involved in the foreign policy decisions of the Russian government. Second, this denigrates Eurovision itself. You don’t have to cheer (although you should) but keep the negative reactions to yourself.

Portugal (video)

This was by far the best stereotypical Eurovison song of the night. Upbeat & vibrant, tons of sequins, and oozing sex appeal. Suzy nailed it with a brilliant performance that had you wanting to dance all night. How this did not make it is beyond me as the best song of this type in the contest always makes it to the finals. Portugal tends to be ignored in this contest and in this case that’s a crime.

San Marino (video)

This is Valentina’s 3rd time and she made it to the final this year. I think this was her best song of the 3 years and it was by far the best staging of the 3 years. The Venus on the half shell staging was simple, elegant, and the perfect framing for her. And she then sang a really beautiful song and did so with her amazing voice.

Montenegro (video)

This one sneaks up on you. You have an ice skater (roller blades) skating around and this big unassuming guy just walking up and starting to sing. And without you realizing it, he reaches out and grabs you and pulls you into the song. Beautiful evocative song that totally pulls you in.

Moldova (video)

This is good. Really really good. On another day I might swap this and Sweden in positions. Powerful in presentation, in voice, in the song. They nailed it in every way and Cristina is definitely the equal of the other female soloists. It’s a travesty that this did not go on to the final.

Also, who can Romania give its 12 votes to with Moldova out?

Albania (video)

Hersi is a really good singer. And she did an amazing job with her song, singing her heart out. Well worth listening to. It did however come just short of the acts listed above. I’ll keep listening to her and probably other songs of her’s. Hersi represents just how good the best is at Eurovision when someone as good as her is not quite in the top 10.

Estonia (video)

This is a really good song, well sung, with incredible staging. Keep in mind that the vocals are live. Tanja performs amazing acrobatics while delivering a very pretty song. With that said, ignoring the acrobatics, it is still a really good song well sung. Not quite as good as some of the others, but well deserving of being in Eurovision.

Azerbaijan (video)

Azerbaijan is like Ukraine, sending a beautiful woman with an amazing voice, song, & staging to Eurovision every year. Dilara delivers with a great performance. With that said, it didn’t reach out an grab me. I wanted it to, I felt like it should, but it didn’t. So there was some spark missing, to me at least, in this one.

The Netherlands (video)

Personally I think Country Music is God’s way of proving some people have no musical taste. With that said, this was an enjoyable song. They’re definitely a very talented duo and they do a great job with the song. The female half also was easily the funniest and most effusive person at the press conference after the show.

Armenia (video)

Maybe I was expecting too much. Aram is at the top of the polls and is the expected winner. So this should be amazing right? He is good and he sang a good song. It was entertaining and enjoyable. But I don’t think it was at the same level as the other songs of the evening. How this was considered the likely winner is beyond me.

Latvia (video)

This has got to be the happiest group competing. It’s a good song, taking the same approach as Malta last year. But for whatever reason it doesn’t work as well. It’s a fun entry worth watching, but that’s it.

Iceland (video)

I won’t say awful but this was the one song of the evening I could easily have done without. Yes they have a great back-story. Yes the message of the song is important. That doesn’t mean it’s entertaining. The only explanation for this making the top 10 is they have preschoolers on some of the juries (this would explain some other dumb jury votes too).