Archive for September, 2014

A note about DateTime queries in Azure

While running a query in Azure based on the last updated time (I had a DateTime  field in my table), I was not getting the results I expected. I had rows whose last updated time was over an hour ago, and I was running a query that would return all records over an hour old, but I wasn’t getting those rows back.

The problem was that I was using a GETDATE() call in the stored procedure, which was in SQL Azure. However, the time that I was using to pull the records was in my local development environment. The time on the Azure site were quite different than on my system.

There are a couple ways to solve this. Using UTC time is one way. Consistently using the GETDATE() call so that it is used in the same environment is another. (Calling the function only on the SQL Azure database, or passing in a DateTime from an application as a parameter to a stored procedure.) I went with the latter, and it worked fine. Just something to keep in mind.

Leave a comment

404 error when querying an Azure table

I was doing the Azure thing, writing some very useful coding – looking up people by their first name. This is a highly advanced software system, and I may try to get a patent for it, so don’t sell this:

// More code above... 
var table = tableClient.GetTableReference("peoplenames");
 var query = from item in table.CreateQuery<People>()
    where item.PartitionKey == "scott"
    select item;
 foreach (People entity in query)
 {
  string firstName = entity.PartitionKey;
  string lastName = entity.RowKey;
 }

When I ran this code, I got a very curious error:

 An exception of type ‘Microsoft.WindowsAzure.Storage.StorageException’ occurred in Microsoft.WindowsAzure.Storage.dll but was not handled in user code

 Additional information: The remote server returned an error: (404) Not Found.

The reason for this is that the “peoplenames” table didn’t exist. If I had wanted to check if a table existed, I could use the Exists() method:

 if (!table.Exists())
 {
  // Do something
 }

Leave a comment

No Entity Framework provider found for the ADO.NET provider with invariant name ‘System.Data.SqlClient’

This was the message I was getting while trying to run a unit test against my C# project:

No Entity Framework provider found for the ADO.NET provider with invariant name ‘System.Data.SqlClient’

Not pleasant. My web project did have Entity Framework 6.x installed, so what was going on?

The issue wasn’t with my web project, it was with my test project. I needed to have those Entity Framework DLLs in my test project as well. I took the easy way out and installed them via NuGet Console. At the prompt, I entered this:

Install-Package EntityFramework

 

Voila, that was all I needed. But just make sure that when the NuGet Console is open, you change the “Default project” drop down list to point to your test project, not the project with the code to be tested.

Leave a comment