问题
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