错误时尝试在Windows Azure Table中保存(Error when try to sav

2019-08-05 14:35发布

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

   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>

我不知道什么是错的..

Answer 1:

不知道什么导致了错误,但你做错过任何一个context.SaveChanges();

context.ADDUSociate(entity);

“我建议你开始得到模拟器在Visual Studio Azure存储和调试这方面的工作。” 我想你没有安装正确的Azure的SDK。 尝试重新安装和仿真器应该工作。 您可以按照本指南: http://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/



文章来源: Error when try to save in Windows Azure Table