“无效的对象名称'dbo.Memberships'。”在尝试添加新用户时

时间:2012-06-06 22:19:14

标签: c# membership-provider

我在最后一天或两天做了一些事情来打破我的申请。

我有一种方法可以使用成员资格提供程序在成员资格数据库中创建新用户。

e.g。

 public void Create(Consumer consumer)
    {

        MembershipCreateStatus status;
        if (consumer.UserId == Guid.Empty)
        {
            consumer.UserId = Guid.NewGuid();
        }
        if (consumer.ConsumerId == Guid.Empty)
        {
            consumer.ConsumerId = Guid.NewGuid();
        }
        try
        {
            var membershipUser = Membership.CreateUser(consumer.UserName, consumer.Password, consumer.Email, null, null, consumer.IsApproved, consumer.UserId, out status);
....
}

内部异常是

  

{“无效的对象名称'dbo.Memberships'。”}

堆栈跟踪

  

at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior behavior)      at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute [TResultType](ObjectContext context,ObjectParameterCollection parameterValues)      在System.Data.Objects.ObjectQuery 1.GetResults(Nullable 1 forMergeOption)      在System.Data.Objects.ObjectQuery 1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable 1源)      在System.Data.Objects.ELinq.ObjectQueryProvider.b__1 [TResult](IEnumerable 1 sequence) at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable 1查询,表达式queryRoot)      在System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute [S](表达式表达式)      在System.Linq.Queryable.FirstOrDefault [TSource](IQueryable`1 source)      在System.Web.Providers.QueryHelper.GetMembership(MembershipEntities ctx,String applicationName,Guid userId)      at System.Web.Providers.DefaultMembershipProvider.Membership_CreateUser(String applicationName,String userName,String password,String salt,String email,String passwordQuestion,String passwordAnswer,Boolean isApproved,DateTime&amp; createDate,Boolean uniqueEmail,Int32 passwordFormat,Object&amp; providerUserKey)      at System.Web.Providers.DefaultMembershipProvider.CreateUser(String username,String password,String email,String passwordQuestion,String passwordAnswer,Boolean isApproved,Object providerUserKey,MembershipCreateStatus&amp; status)      at System.Web.Security.Membership.CreateUser(String username,String password,String email,String passwordQuestion,String passwordAnswer,Boolean isApproved,Object providerUserKey,MembershipCreateStatus&amp; status)      at Plenfy.Api.Models.ConsumerRepository.Create(Consumer consumer)in c:\ @ Code \ Customers \ Api \ Repository \ ConsumerRepository.cs:line 121

我不知道如何解决问题。数据库和连接字符串看起来很好,我可以用EF连接到它。

任何人都可以建议如何深入了解这一点吗?

1 个答案:

答案 0 :(得分:-1)

try to use 
MembershipCreateStatus status;
        if (consumer.UserId == Guid.Empty)
        {
            consumer.UserId = Guid.NewGuid();
        }
        if (consumer.ConsumerId == Guid.Empty)
        {
            consumer.ConsumerId = Guid.NewGuid();
        }
        try
        {
            var membershipUser = System.Web.Security.Membership.CreateUser(consumer.UserName, consumer.Password, consumer.Email, null, null, consumer.IsApproved, consumer.UserId, out status);
        }