-1

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

   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>

不知道怎么回事。。

4

1 回答 1

0

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

context.ADDUSociate(entity);

"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/

于 2013-01-04T14:30:54.020 回答