I am finding that the development storage emulator has a few “undocumented features”. A few days ago, I was happily working through the Windows Azure Training Kit and things were going well. Today I was putting together a PoC using pieces learnt from the labs. I kept hitting a problem when trying to insert an entity into the newly created table storage (running on the local Storage Emulator). I was getting the generic error message when querying the collection:
“one of the request inputs is not valid”
var match = (from c in this.context.Clients
where c.Name == name
Some things I tried that didn’t help:
- Restarting the Storage Emulator a few times.
- Restarting the machine (always worth a shot!)
- Deleting the entries in the TableContainer and TableRow tables in the development storage DB.
- Recreating the development storage DB using DSINIT /forceCreate.
- Running around the office naked.
After hunting around for quite some time (including running the lab code again and getting them same result) I tracked it down to the table storage schema not being created after issuing
Note: This worked happily when I was working through the labs a few days ago. Neither my code nor the lab code was working now.
Looking at the underlying DB (using SQLEXPRESS on my VM) I found no schema populated
After some frustrating searching, I came across this post that suggested an ugly work around > azure-table-storage-what-a-pain-in-the-ass. It suggests that on the local storage emulator you need to “convince” the table service provider that you know what you are doing by inserting some dummy entities. This only appears to be needed when you have no data in your tables. So I added the following code in my data source constructor so it gets called by my service before performing any CRUD operations.
// [WORK AROUND] See http://deeperdesign.wordpress.com/2010/03/10/azure-table-storage-what-a-pain-in-the-ass/
// Generate some inserts to populate empty table
var client = new Client("dummy", "dummy");
var post = new Post("dummy", "dummy");
Ugly but it jumps the hurdle and allows me to get back to building out the rest of the solution. Just remember to comment it back out after you verify the schema xml has been populated successfully and your CRUD operations are going through.