错误时试图保存在Windows Azure的表错误、存在、Azure、Windows

2023-09-03 08:18:27 作者:蹲在墙角唱领悟

我做这在存储添加用户的方法。下面是code,而我得到的错误。

I did a method which add a user in storage. Below is the code and the error that I'm getting.

   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>

我不知道什么是错。

I don't know what is wrong..

推荐答案

不知道什么导致错误,但你错过 context.SaveChanges();

Not sure whats causing the error but you do miss a context.SaveChanges(); after

context.ADDUSociate(entity);

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

"I suggest you start with getting the emulator working for azure storage and debug this in visual studio." I think you dont have the correct Azure sdk installed. Try to reinstall it and the emulator should work. You can follow this guide: http://www.windowsazure.com/en-us/develop/net/how-to-guides/blob-storage/