Db update Exception由用户代码处理 [英] Db update Exception was handle by user code

查看:66
本文介绍了Db update Exception由用户代码处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建按钮代码:



create button code:

<br />
<br />
public ActionResult Create()<br />
        {<br />
            return View();<br />
        }<br />
<br />
        // POST: authors/Create<br />
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for <br />
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.<br />
        [HttpPost]<br />
        [ValidateAntiForgeryToken]<br />
        public ActionResult Create([Bind(Include = "au_id,au_lname,au_fname,phone,address,city,state,zip,contract")] author author)<br />
        {<br />
            if (ModelState.IsValid)<br />
            {<br />
                db.authors.Add(author);<br />
                db.SaveChanges();<br />
                return RedirectToAction("Index");<br />
            }<br />
<br />
            return View(author);<br />
        }<br />
<br />





删除按钮代码:





Delete Button code:

<br />
<br />
public ActionResult Delete(string id)<br />
        {<br />
            if (id == null)<br />
            {<br />
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);<br />
            }<br />
            author author = db.authors.Find(id);<br />
            if (author == null)<br />
            {<br />
                return HttpNotFound();<br />
            }<br />
            return View(author);<br />
        }<br />
<br />
        // POST: authors/Delete/5<br />
        [HttpPost, ActionName("Delete")]<br />
        [ValidateAntiForgeryToken]<br />
        public ActionResult DeleteConfirmed(string id)<br />
        {<br />
            author author = db.authors.Find(id);<br />
            db.authors.Remove(author);<br />
            db.SaveChanges();<br />
            return RedirectToAction("Index");<br />
        }<br />
<br />







错误位置为

db.save更改引发错误。

错误如Db update Exception被用户代码处理



请帮助我,



谢谢你




same error will be raise in create and delete methods that error location is
db.save changes raise a error.
error like as "Db update Exception was handle by user code"

pls help me,

thank u

推荐答案

我认为你正在使用EntityFramework,所以请确保连接字符串在web.config文件中可用。当您添加实体框架时,它会要求您将敏感数据添加到项目中。我想你会选择不。试试这个并告诉我。
I think you are using EntityFramework, so please make sure that the connection string is available in the web.config file. When you are adding the entity framework it will asks for you to add the sensitive data into the project or not. I think you would have select no. Try this and let me know.


这篇关于Db update Exception由用户代码处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆