Error :An Exception occurred while initializing the database. See the Innerexception for Details

Asked

Viewed 110 times

1

Someone could help me in this era that I always come across him and after numerous attempts, I can not find this error, I am developing an application in MVC 3 exploring more this part of the Code First. Could someone help me with this?

It follows the code, and the error it gives as soon as I compile the solution:

public class ClienteController : Controller
{
    private BancoContexto db = new BancoContexto();

    public ViewResult Index()
    {
            return View(db.Clientes.ToList());
    }


    public ViewResult Details(int id)
    {
        //Cliente cliente = db.Clientes.Find(id);
        Cliente cliente = db.Clientes.Include("Vendas")
             .Include("Produtos")
            .Single(p => p.IDCliente == id);
        return View(cliente);
    }


    public ActionResult Create()
    {
        return View();
    } 



    [HttpPost]
    public ActionResult Create(Cliente cliente)
    {
        if (ModelState.IsValid)
        {
            db.Clientes.Add(cliente);
            db.SaveChanges();
            return RedirectToAction("Index");  
        }

        return View(cliente);
    }


    public ActionResult Edit(int id)
    {
        Cliente cliente = db.Clientes.Find(id);
        return View(cliente);
    }


    [HttpPost]
    public ActionResult Edit(Cliente cliente)
    {
        if (ModelState.IsValid)
        {
            db.Entry(cliente).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(cliente);
    }

    public ActionResult Delete(int id)
    {
        Cliente cliente = db.Clientes.Find(id);
        return View(cliente);
    }


    [HttpPost, ActionName("Delete")]
    public ActionResult DeleteConfirmed(int id)
    {            
        Cliente cliente = db.Clientes.Find(id);
        db.Clientes.Remove(cliente);
        db.SaveChanges();
        return RedirectToAction("Index");
    }

    protected override void Dispose(bool disposing)
    {
        db.Dispose();
        base.Dispose(disposing);
    }
}

}

The error is attached:

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.