C# / accdb: Getting error “Operation must use an updateable query.”

三世轮回 提交于 2019-12-24 07:15:06

问题


I'm writing an application in C# which connects to an MS Access database (.accdb). The application will be used by several workers and each of them will get connected to the db from time to time - to refresh their presence (refresh the sign-in time).

All other functions which connect to the same database seem to work fine but this one doesn't. I'm getting the below error for some reason and it says the problem is in the line where my ExecuteNonQuery() is. The command text is defined with the string myUpdateNonquery.

System.Data.OleDb.OleDbException (0x80004005): Operation must use an updateable query.

The function:

public Boolean RefreshSignIn()
{
  Boolean successful = false;
  lock(dbLock)
  {
    try
    {
      string myConnectionString = connectionType + primarydbPath;
      OleDbConnection myConnection = new OleDbConnection(myConnectionString);
      string myUpdateNonquery = "UPDATE AgentSignIn SET signInTime = NOW() WHERE agentName = @p1";
      using(myConnection)
      {
        OleDbCommand myCommand = new OleDbCommand(myUpdateNonquery, myConnection);
        using(myCommand)
        {
          myCommand.Parameters.Add("@p1", OleDbType.Char).Value = appSettings.mynick;

          myConnection.Open();
          int updatedRows = myCommand.ExecuteNonQuery();
          if (updatedRows>0) {successful = true;}
        }
      }
    }
    catch(System.Exception ex)
    {
      MessageBox.Show("Error! Failed to keep you signed in to the database!\n\n"+ex.ToString());
    }
  }
  return successful;
}

回答1:


The SQL looks fine. It seems to be a permission issue, the article below outlines how to fix this issue:

http://www.mikesdotnetting.com/Article/74/Solving-the-Operation-Must-Use-An-Updateable-Query-error



来源:https://stackoverflow.com/questions/10138493/c-sharp-accdb-getting-error-operation-must-use-an-updateable-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!