Visual Studio 2013 SQL Server Database Projects

Visual Studio is a large application with so many features that you sometimes you stumble into a new one and think if I had know that 3 years ago. With all the hype over new features like Code Lens, Peek Definition and ASP.NET Integration there are some features that aren’t as flashy and don’t get the attention they deserve…

SQL Server Database Projects

A co-worker of mine, Floyd, (you can find him at @fhilton) recently discovered SQL Server Database Project templates and data tools and I think he found a gold mine:

Visual Studio 2013 SQL Server Database Project Template

A Database project is associated with a SQL Server database and allows for developers to pull in all the various assets of the database and use source control. You can also start a new database using the template and deploy right from Visual Studio.

The Features

There are two many exciting features to cover them all but here’s a list of my favorite so far:

  • Schema comparison - compare schemas between your development database and production
  • Data comparison - compare data between different databases
  • Source Control - Yes, Source Control for your SQL
  • Change Script generation
  • Unit Testing - Yes, Unit Testing (what is this craziness?)
  • Generate Snapshots - Snapshots are a point in time version of the database that you can do a schema compare against
  • Re-factoring support - Rename a table or column and have all your stored procedures update!
  • Deployment
  • Windows Azure SQL Database Support

And don’t worry you can do all your ad hoc SQL queries right from Visual studio without having to boot up SSMS. You can find out more about the tooling from the Channel 9 video Introducing SQL Server Database Projects Tooling in Visual Studio 2013

I have only just started to explore the tools but can tell it is going to improve my team’s database management practices. In what ways do you see your self using these tools? What must try features have I missed?

Music and The Flow

As developers we are often searching for The Flow… that special place where we are fully focused and making things happen. Music is often an important part of the developers ability to get into The Flow. Headphones and music could be the only thing that gets you through the busy (and loud) morning in the office. Sometimes even that doesn’t work.

Recently, there have been a lot of tools coming out to help. Everything from a music service that helps you focus to Brain Similators that gives a small electric current to you prefrontal cortex. There is even an industry leader, Carl Franklin, who is started a kickstarter, Music to code by, to create his own music that is designed specifically for getting into the flow while coding.

Finding Your Music Flow

Unfortunately it isn’t as easy as simply putting on headphones and turning the music up. Having clear goals (Trello helps me) and a immediate feedback loop (some sort of testing loop) are important but so is your music choice.

I found that the type of task and project I am working on is conductive to different types of music. Almost always it is music without lyrics. Here are few options I have found helpful:

  • While Creating new features I like to have Up-tempo music that helps me channel creativity.
  • When Re-factoring I like to have Chill/Down-Tempo music that helps me relax and concentrate on the task at hand.
  • For Complex tasks it is plain Acoustical Guitar music that will help me solve the problem.
  • When I am Bored or Upset I tend to listen to Classical music. It is hard to be upset when listening to Beethoven.

Whatever your music style take some time to try different types and reflect on how the music choice helped you accomplish your task and get you into The Flow. Experiment and have fun, everyone will have different preferences. And don’t forget to leave a comment to let me know what your preferences are. Enjoy the music and The Flow.

MultiValue Dictionary

The .NET team had been working on modularizing and shipping code faster than it has in the past. One mechanism it has been using to release code earlier and faster is NuGet. Using Nuget they are able to ship us pre-release software that we can experiment with. Enter the MultiValueDictionary.

A Dictionary of Lists

Many of applications have the need for keeping track of a key and lists associated with them. An example I came across recently was storing user roles in memory. A single user could have multiple roles and so a standard dictionary would not work. Traditionally, this meant having a dictionary of lists like so:

var roles = new Dictionary<string, List<Role>>();

Accessing the roles and adding a new role was cumbersome. The code to access the list and add new roles could be abstracted away into a class that wrapped this data structure and provided simpler methods. Until now that had to be done by the developer.

MultiValue Dictionary

Using NuGet, Microsoft has shipped a pre-lease version of the the MultiValueDictionary which provides this functionality as part of the framework:

var roles = new MultiValueDictionary<string, Role>();
roles.Add("id", new Role());

You can find out more about the use of this data structure from the Microsoft blog post introducing the MultiValueDictionary. This is in pre-release but the functionality is exciting. Hope you get to check it out.

Coding with music

The headphones go on and the sounds soften. That much closer to the fable zone. The bass starts and the feeling of focus begins to take over. No more distractions, only the world created yesterday beckoning for exploration. The melody leads the way as the world takes takes shape…

“Hey, when is that new feature going to be done?”

“Tomorrow…”

The headphones go back on and the sounds soften. That much closer to the fabled zone

OAuth 2.0 Flows

I have been doing a lot research on OAuth 2.0 recently and have found that most articles assume that you know the specification and focus on only one type of flow. To make matter’s worse some authorization services only offer some of the flows (for example Azure Active Directory). This lead to some confusion until I read enough articles to cover all the OAuth 2.0 flows.

Below is a very high level overview of the numerous OAuth 2.0 Flows. It does not go into the details of the flows and should only be used as a reference.

The Flows

Resource Owner Password Flow

The user gives the client their credentials and the client goes directly to the Authorization server and is returned an Access token.

This is one of the simplest flow of the OAuth 2.0 protocol and also the most surprising. It is surprising because the user shares their credentials with client, which is contradictory to the purpose of the OAuth protocol.

Authorization Grant Flow

The user is redirected to the Authorization server and is given an Authorization Token. The client then goes back to the Authorization server and exchanges the Authorization Token for an Access token.

In this flow the client never has access to the user’s credentials.

Implicit Flow

The user is redirected to the Authorization Server to authenticate and the client is directly given an Access Token. The difference between this and the Resource Owner Password Flow is that the client is never privy to the user’s credentials.

Client Flow

In this flow the user is not involved and does not grant access to any of the user’s resources. Instead the client goes to the authorization server and gains access to resources that the client owns.

Other Resources

Check out HyTech’s Oauth2 Introduction for a deeper discussion of the the flows.

I also found Designing Evolvable Web APIs with ASP.NET’s chapter on OAuth 2.0 helpful.

And there is always the OAuth 2.0 spec itself.