使用mvc4 razor连接到mysql数据库c#[错误]

时间:2013-04-28 11:25:36

标签: c# asp.net mysql razor

hi guyz我去了这个错误代码:执行命令定义时发生错误。有关详细信息,请参阅内部异常。,将我的文本搜索到数据库..

        private bool IsValidRegisterNewAcct(string acctname, string dispname, string email, string password)
    {
        var crypto = new SimpleCrypto.PBKDF2();
        bool IsValid = false;
        IsValidErrorMessage = "";
        IsValidErrorMessageInt = 0;
        string Newacctname = crypto.Compute(acctname.ToString());
        //try
        //{
            using (var db = new MainDbContext())
            {

                //db.Connection.Open();
                var user = db.user.FirstOrDefault(u => u.AcctNameSalt  == Newacctname);
                //var user = db.osoa_user.FirstOrDefault(u => u.Email == email);

                if (user != null)
                {
                    IsValid = false;
                    //db.Connection.Close();
                    IsValidErrorMessage = "Account Name already Exist!";
                }
                else
                {
                    var InsertNewAcctName = db.osoa_user.CreateObject();

                    InsertNewAcctName.UserId = Convert.ToString( Guid.NewGuid());
                    InsertNewAcctName.AcctName = acctname;
                    InsertNewAcctName.AcctNameSalt = crypto.Compute(acctname);
                    InsertNewAcctName.DisplayName = dispname;
                    InsertNewAcctName.Email = email;
                    InsertNewAcctName.EmailSalt = crypto.Compute(email);
                    InsertNewAcctName.Password = crypto.Compute(password);
                    InsertNewAcctName.PasswordSalt = crypto.Salt;
                    InsertNewAcctName.UserLevel = 2;

                    db.user.AddObject(InsertNewAcctName);

                    db.SaveChanges();
                    //db.Connection.Close();
                    IsValid = true;
                }
            }
        /*
        }
        catch (Exception e)
        {
            IsValidErrorMessageInt = 1;
            IsValidErrorMessage = e.Message + ". Pls. contact your Administrator.";
            IsValid = false;
        }
        */
        return IsValid;

    }

并且错误指向此代码:

var user = db.user.FirstOrDefault(u => u.AcctNameSalt  == Newacctname);

更新关于内部异常。我不知道是否给你正确的..我试着使用这段代码:

            try
        {
        }
        catch (Exception e)
        {
            IsValidErrorMessageInt = 1;
            IsValidErrorMessage = e.InnerException + ". Pls. contact your Administrator.";
            IsValid = false;
        }

MySql.Data.MySqlClient.MySqlException(0x80004005):MySql.Data.MySqlClient.NativeDriver中MySql.Data.MySqlClient.MySqlStream.ReadPacket()的“字段列表”中的未知列“Extent1.DateCreated”。 GetSesult(Int32& affectedRow,Int64& insertedId)位于MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId,Int32& affectedRows,Int64& insertedId)的MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId,Boolean force)at at在System.Data.Common.DbCommand.ExecuteReader的MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior行为)的MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior行为)中的MySql.Data.MySqlClient.MySqlDataReader.NextResult() System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand,CommandBehavior behavior)

的CommandBehavior行为)

1 个答案:

答案 0 :(得分:0)

从您的内部异常看起来好像您的MainDbContext已经与您的数据库不同步(看起来Extent1有一个在数据库中不存在的列)。

尝试从模型中删除该属性,然后重试。