【问题标题】:Error when try to save in Windows Azure Table尝试在 Windows Azure 表中保存时出错
【发布时间】:2012-12-18 21:10:06
【问题描述】:

我做了一个在存储中添加用户的方法。下面是我得到的代码和错误。

   public string addusr(string nome, string cidade, string cpf, string email, string telefone)
    {
        try
        {
            if (nome.Length == 0)
                return "f:Preencha o campo nome.";

            if (cidade.Length == 0)
                return "f:Preencha o campo cidade.";

            if (cpf.Length == 0)
                return "f:Preencha o campo cpf.";

            if (!Valida(cpf))
                return "f:CPF Invalido.";

            if (email.Length == 0)
                return "f:Preencha o campo email.";

            Regex rg = new Regex(@"^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$");
            if (!rg.IsMatch(email))
            {
                return "f:Email Invalido";
            }

            List<UserEntity> lst = new List<UserEntity>();
            var _account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
            var _context = new CRUDUserEntities(_account.TableEndpoint.ToString(), _account.Credentials);
            if (_context.Select(cpf).Count() > 0)
                return "dup";

            var account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("Conn"));
            var context = new CRUDUserEntities(account.TableEndpoint.ToString(), account.Credentials);
            UserClientEntity entity = new UserClientEntity() { nome = nome, cidade = cidade, cpf = cpf, email = email, telefone = telefone };
            context.ADDUSociate(entity);
            return "k";
        }
        catch (Exception exc)
        {
            string error =  "f:" + exc.Message + "|" + exc.StackTrace;
           // Trace.WriteLine("Erro no login: " + error , "Information");
            return error;
        }
    }

当我尝试添加用户时...出现此错误:

    <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
      f:An error occurred while processing this request.| at            Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result()
         at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.ExecuteAndWait()
        at Microsoft.WindowsAzure.StorageClient.CommonUtils.      <LazyEnumerateSegmented>d__0`1.MoveNext()
        at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
        at mobile.Service1.addusr(String nome, String cidade, String cpf, String email, String telefone)
    </string>

我不知道怎么了..

【问题讨论】:

  • 在模拟器上能用吗?
  • 我没有在模拟器中跑过……这里模拟器不工作。当我尝试模拟“系统缺少执行服务的先决条件,请参阅输出窗口以获取更多信息”时出现此错误。
  • 我建议你先让模拟器为 Azure 存储工作,然后在 Visual Studio 中调试它。
  • 了解错误类型以及错误消息会很有用,因此您可能需要改进 try...catch 块。你是在设置分区键和行键吗,这段代码我看不到。

标签: asp.net .net azure azure-storage


【解决方案1】:

不确定是什么导致了错误,但你确实错过了context.SaveChanges();

context.ADDUSociate(entity);

“我建议你先让模拟器为 Azure 存储工作,然后在 Visual Studio 中调试它。” 我认为您没有安装正确的 Azure sdk。尝试重新安装它,模拟器应该可以工作。您可以按照本指南:http://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/

【讨论】:

    猜你喜欢
    • 2017-08-07
    • 2012-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 2014-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多