Home  >  Article  >  Database  >  Access数据库提示OleDbException (0x80004005): 操作必须使用一

Access数据库提示OleDbException (0x80004005): 操作必须使用一

WBOY
WBOYOriginal
2016-06-07 18:07:231361browse

使用Access当数据库时,这个问题郁闷了我好几天啊![OleDbException (0x80004005): 操作必须使用一个可更新的查询。]

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Data.OleDb.OleDbException: 无法从指定的数据表中删除。

源错误:


行 37: comm.CommandText = sqlstr;
行 38: //comm.Prepare();
行 39: cout = comm.ExecuteNonQuery();
行 40:
行 41: conn.Close();


源文件: d:\SOVO验收代码\Base\App_Code\JetAccess.cs 行: 39

[OleDbException (0x80004005): 无法从指定的数据表中删除。]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +267
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +192
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +48
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +106
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +108
JetAccess.Execute(OleDbParameter[] parameters, String sqlstr) in d:\SOVO验收代码\Base\App_Code\JetAccess.cs:39
NewsData.DeleteNews(Int32 id) in d:\SOVO验收代码\Base\App_Code\NewsData.cs:29
_Default.GridView1_RowDeleting(Object sender, GridViewDeleteEventArgs e) in d:\SOVO验收代码\Base\System\Default.aspx.cs:46
System.Web.UI.WebControls.GridView.OnRowDeleting(GridViewDeleteEventArgs e) +133
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +604
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +1155
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +199
System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +174
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

解决方法如下:
在数据文件*.mdb上右键打开属性对话框,在'安全'标签下需要添加IUSR_XXX(XXX为你的机器名),也就是添加Internet Guest Account帐户,再将此帐户的权限设为可读,可写.(原来这么简单就解决了的问题,我靠:) )
如果在右键属性对话框内找不到'安全'标签,需要将文件夹选项下的视图内的'使用简单文件共享(默认)'的勾去掉.

原因:
有几个主要的错误原因:
这个错误发生在当你的程序试图执行更新数据库或其它类似操作时。这是因为
ADO由于以下的几个原因而不能够写数据库造成的。
1。最普遍的原因是匿名用户帐号(IUSR_MACHINE)对该数据库文件没有写权限。
要解决这个问题,在管理器中调整数据库文件的属性,让匿名用户有正确的权限。
当使用ACCESS数据库时,不仅要给文件写的权限,还要给该目录写 的权限,因为
Jet需要在该目录建立一个.ldb文件。
2。第二个原因是数据库没有使用正确的模式打开。应该使用下面的方法打开。
SQL = "UPDATE Products Set UnitPrice = 2;"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Mode = 3 ''3 = adModeReadWrite
Conn.Open "myDSN"
Conn.Execute(SQL)
Conn.Close
注意默认的Mode是设置0(adModeUnknown),它是允许更新的。
3。还有可能是在ODBC管理器中将该DSN的只读选项选中。
4。你是在同时更新两个表中的字段,也会出现这个错误信息,解决办法是分开来更新
这两个表中各自字段。
5。当你使用了一个从低版本中(如ACCESS2.0,ACCESS7.0)载入到高版本(ACCESS 2000)
中的查询时,在执行这个查询是会出现该错误。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn