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

问题描述 投票:0回答:1

我在我的班级模型用户中添加了一个属性“密码”。它现在在我看来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");
}
c# asp.net asp.net-mvc-4 ef-migrations
1个回答
-1
投票

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

尝试

SP_WHO看谁有联系

KILL如果需要或使用using (context db = new context())

© www.soinside.com 2019 - 2024. All rights reserved.