System.Data.SqlClient.SqlException:'无法删除数据库。怎么解决?

时间:2018-02-28 11:00:43

标签: c# asp.net asp.net-mvc-4 ef-migrations

我添加了一个属性"密码"在我的班级模型用户。它现在显示在Register.cshtml {。}}。

 <form action="~/Users/SaveRegister" method="post">

            @Html.ValidationSummary(true)

            @Html.AntiForgeryToken()
            <div class="editor-label">
                @Html.LabelFor(model => model.user_name)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.user_name)
                @Html.ValidationMessageFor(model => model.user_name)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.password)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model.password)
                @Html.ValidationMessageFor(model => model.password)
            </div>
            <p>
                <input type="submit" value="Register" />
            </p>
    </form>

但是当我按db.Users.Add(User);时,它会在我的控制器Register中提供例外。

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SaveRegister(Airlineapp.Models.User User, HttpPostedFileBase file)
{

    db.Users.Add(User);
    db.SaveChanges();
    return RedirectToAction("Index");
}

1 个答案:

答案 0 :(得分:-1)

有人连接到数据库。尝试切换到另一个数据库,然后删除它:

尝试

SP_WHO看看谁联系了

如果需要,请

KILL或使用using (context db = new context())