Using WebAPI with ASP MVC 3

If you are like me where in your organization you are using the membership provider that came with ASP MVC 3 template but you also have the need to provide RESTful services from within the same application and would really really like to use the awesome WebAPI, here is what you need to do:

  1. Create a brand new MVC 3 internet application or open up your existing application
  2. Install the following NuGet Package using the package manager console:

  3. Open the Global.asax file and add the following route after this routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); line as shown:

  4. Also ensure that you have used or imported System.Web.Http depending on C# / VB in Global.asax like so:

  5. Add a new WebAPI controller using the Add -> New Item context menu option or just use Ctrl + Shift + A keyboard shortcut.

I believe this is a lot easier than starting a MVC4 application and trying to incorporate the membership provider into that.


Force MySQL to be case sensitive in Windows

I develop on Windows / Linux and deploy on Linux. I always run into the issue of my tables having different cases on my development and production environments causing stupid time wasting errors. If only everything in this world was nice. Hold your breath! There is a work around.

I don’t know why this is not default by design but according to the Identifier Case Sensitivity section in the manual:

How table and database names are stored on disk and used in MySQL is affected by the lower_case_table_names system variable, which you can set when starting mysqld. lower_case_table_names can take the values shown in the following table. This variable does not affect case sensitivity of trigger identifiers. On Unix, the default value of lower_case_table_names is 0. On Windows the default value is 1. On Mac OS X, the default value is 2.

0 – Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement. Name comparisons are case sensitive. You should not set this variable to 0 if you are running MySQL on a system that has case-insensitive file names (such as Windows or Mac OS X). If you force this variable to 0 with –lower-case-table-names=0 on a case-insensitive file system and access MyISAM tablenames using different lettercases, index corruption may result.

1 – Table names are stored in lowercase on disk and name comparisons are not case sensitive. MySQL converts all table names to lowercase on storage and lookup. This behavior also applies to database names and table aliases.

2 – Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE DATABASE statement, but MySQL converts them to lowercase on lookup. Name comparisons are not case sensitive. This works only on file systems that are not case sensitive! InnoDB table names are stored in lowercase, as for lower_case_table_names=1.

The best option to simulate this behavior in Windows is to set lower_case_table_names = 2 in your my.ini file. In my Windows 8 for a MySQL 5.6 server install, this file is located at C:\ProgramData\MySQL\MySQL Server 5.6\my.ini. Depending on your installation, this path my be a little different. Open the file and update the value of the lower_case_table_names variable or if it is not present just add the value to the end of the file.

Remember to restart the MySQL service in Windows by running services.msc. Grab a beer and keep rocking!

Reset the Start Screen in Windows 8

The Metro Start Screen is a new concept to a lot of us. So we experiment at first and after a lot of time spent, we come to start using Metro in a way that suits us most. Personally I cluttered up the start screen with all my icons and I realized that it is way easier to open any application by just hitting the Start key and just typing its name rather than click on a tile. So I decided to reset my Start screen.

Open an elevated command prompt. There are many ways to do this. The easiest way to do it is to hit Windows + A. When you see the popup menu, choose Command Prompt (Admin) or simply hit A.

Once the command prompt opens, run the following commands:

Now when you hit the Start key, Explorer will restart and you will have the stock menu. Keep it this way or customize it to your liking again.

Trouble installing Virtualbox Guest Additions in Ubuntu 13.04 Raring Ringtail?

I recently setup the latest and greatest (13.04) on my laptop. I still have to work on Visual Studio so I installed Virtualbox (4.2.12) to setup a Windows VM.

All goes well until the point where you have to install the guest additions as it is needed for the USB support. Now a dialog box shows up prompting you for your password. Here’s the kicker: no matter what you put in, even if is the CORRECT password, it’ll tell you have entered a wrong password and not let you continue.

I did a lit bit of searching on the internet and found the answer here.

Pull up a terminal and type this:

where you would substitute with the name of the guest additions extension pack like so:

The Maker’s Schedule & The Manager’s Schedule

Here is another great thought from Paul Graham that I might embrace on how to be a maker and manager:

When we were working on our own startup, back in the 90s, I evolved another trick for partitioning the day. I used to program from dinner till about 3 am every day, because at night no one could interrupt me. Then I’d sleep till about 11 am, and come in and work until dinner on what I called “business stuff.” I never thought of it in these terms, but in effect I had two workdays each day, one on the manager’s schedule and one on the maker’s.

No body tells this to beginners!

Found this great quote by Ira Glass at NPR Fresh Air’s Tumblr:

Nobody tells this to people who are beginners, I wish someone told me. All of us who do creative work, we get into it because we have good taste. But there is this gap. For the first couple years you make stuff, it’s just not that good. It’s trying to be good, it has potential, but it’s not. But your taste, the thing that got you into the game, is still killer. And your taste is why your work disappoints you. A lot of people never get past this phase, they quit.

Using MySQL Connector .NET 6.6.4 with Entity Framework 5

I had been waiting for the latest MySQL connector for .NET to come out so I can move on to the new and sleek Visual Studio 2012 for my projects. Found out connector 6.6.4 has been out which can work with VS2012 so I happily install it. I start a brand new project and start setting up the Membership and Roles using the MySQL Website Configuration tool and everything worked great. To give you some more additional info about the project setup it is targeting .NET Framework 4 and the type of project is a MVC 3 web application using Razor.

Now it was time to let the code first magic happen. I create my models and then issue an Enable-Migration  via the package manager console. The migrations are setup. Next I issue the Add-Migration Initial  to create the initial scaffolding for my model and I get the following error:

No MigrationSqlGenerator found for provider ‘MySql.Data.MySqlClient’. Use the SetSqlGenerator method in the target migrations configuration class to register additional SQL generators.

Upon doing some research I find out that for the connector version 6.6.4, we’ll have to explicitly set up the SQL code generator. Open Configuration.cs  file found in the Migrations  folder and add the following line to the constructor

After doing that I re-run my Add-Migation Initial  command and the scaffolding is generated without any issues this time.

It is time to create the schema and tables. I issue Update-Database -Verbose  command now and stumble upon another issue this time which is:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.IO.FileLoadException: Could not load file or assembly ‘EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Upon more research I find out that connector 6.6.4 will not work with Entity Framework 5 but with Entity Framework 4.3. So to downgrade issue the following commands in the package manager console:


Finally I do Update-Database -Verbose  again and voila! The schema and tables are created. Wait for the next version of connector to use it with Entity Framework 5.

Niagara Falls on a clear winter day

I was spending a weekend at the Niagara Falls State Park and got this beautiful shot.

Niagra Falls on a clear day in winter

MySQL Workbench – Error Code: 1175

Have you ever encountered the following error while using MySQL workbench?

This is a safety feature which has been implemented to prevent bad queries from destroying your table. But we know our query is right and that it has to run. So what do we do?

There are 2 ways to proceed from here:

  • a temporary fix
  • a permanent fix

For a temporary fix, here is what you need to do:

No application restart required.

For a more permanent fix, do this:




Concatenate WAV files in Java

Here is a small snippet that will let you concatenate a list of WAV files. This only works for WAV files and is based on the assumption that all files are of the same format.

While the core code is good for most people, I’m sure the nuances of your needs are different than mine so you can modify or extend that above as necessary.

Happy coding!