简体   繁体   中英

Exception of type Microsoft.WindowsAzure.StorageClient.StorageClientException was thrown

I am trying to write a simple program to get familiar with Azure. I get the above exception on the CreateTableIfNotExist(..) line. Please help. Here is the code:

    public ActionResult Index()
    {
        var client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudTableClient();

        var success = client.CreateTableIfNotExist("Messages");

        var svc = client.GetDataServiceContext();


        //"Messages" is the name of the table
        return View(svc.CreateQuery<Message>("Messages").AsTableServiceQuery());
    }

Here is the stack trace:

at Microsoft.WindowsAzure.StorageClient.Tasks.Task 1.get_Result() at Microsoft.WindowsAzure.StorageClient.Tasks.Task 1.ExecuteAndWait() at Microsoft.WindowsAzure.StorageClient.TaskImplHelper.ExecuteImpl[T](Func 2 impl) at Microsoft.WindowsAzure.StorageClient.CloudTableClient.CreateTableIfNotExist(String tableName) at MvcWebRole1.Controllers.HomeController.Index() in C:\\tests\\AzureDemo\\MvcWebRole1\\Controllers\\HomeController.cs:line 18 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary 2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary 2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func 2 parameters) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func 1 continuation)

Also, I see in the web page, it says 'resource not found'. Not sure what resource it is looking for.

Are you using development storage? If so I would highly recommend that you read Differences Between Development Storage and Windows Azure Storage Services .

It sounds like you are hitting the issue that is unique to development storage in which you cannot query a table that has never contained any entities:

In development storage, querying on a property that does not exist in the table returns an error. Such a query does not return an error in the cloud.

A dev storage workaround is documented here :

[E]nsure that the table storage knows about the structure of your objects.

var query = from x in context.CreateQuery(VehicleTableName) select x;
var l = query.ToList();
var v = new Vehicle();
context.AddVehicle(v);
context.SaveChanges();
context.DeleteObject(v);
context.SaveChanges();

Well, I finally went past the error today. Hope the info below helps the rest of you. Not sure what I was doing wrong before but I simply made sure:

  1. I left it alone for a few days ;)
  2. The app is run with VisualStudio 2010 in ADMIN mode.
  3. The Azure project (the one with the blue globe) is set as startup object. Hence hit F5 to run the whole app.
  4. Your Compute Emulator and Storage Emulator are started (check the sys tray on the bottom right of your screen).

I am quite sure I had all this covered when I got the error before but I can't always trust myself.

Hope this helps.

And thanks to Steve Marx for the nice demo code and pdc video . Has really helped me learn stuff.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM