0
votes

hi guyz i've go this error code: An error occurred while executing the command definition. See the inner exception for details. in searching my text to the database..

        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;

    }

and the error was pointing to this code:

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

UPDATE About the Inner exception. i dont know if give you the correct one.. i tried to use this code:

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

MySql.Data.MySqlClient.MySqlException (0x80004005): Unknown column 'Extent1.DateCreated' in 'field list' at MySql.Data.MySqlClient.MySqlStream.ReadPacket() at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId) at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) at MySql.Data.MySqlClient.MySqlDataReader.NextResult() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

1
Have you looked to the inner exception?Kai
and the inner exception says....?rene

1 Answers

0
votes

From your inner exception it appears as though your MainDbContext has became out of sync with your database (looks like Extent1 has a column which doesn't exist in the DB).

Try removing that property from the model and trying again.